mpi-caraudio.nl Posted September 23, 2005 Posted September 23, 2005 have downloaded and installed this contrib. stumbled on a problem... :huh: searched the forum... tried the latest thumbnailer contrib... didnt work at all on my site... :blush: so changed it back to the other automatic thumbnail contrib. decided to post yet another image resize question... :-" For my use all thumbs should be 150 x 150. However in my settings I use 50 x 50 for product listing and 150 x 150 for everything else (made a small change to a PHP to support that of course). How can I change this code to make thumbs of 1 defined size (150x150)? This is the code used for this contribution in: includes\functions\html_output.php //// // The HTML image wrapper function ?function tep_image($src, $alt = '', $width = '', $height = '', $parameters = '') { ? ?if ( (empty($src) || ($src == DIR_WS_IMAGES)) && (IMAGE_REQUIRED == 'false') ) { ? ? ?return false; ? ?} ? ?if ($image_size = @getimagesize($src)) { ? ? ?if ((CONFIG_CALCULATE_IMAGE_SIZE == 'true' && $src != DIR_WS_IMAGES . 'pixel_black.gif' && $src != DIR_WS_IMAGES . 'pixel_trans.gif' && $src != DIR_WS_IMAGES . 'pixel_silver.gif' )) { ?if ( ($width) || ($height) ) { ? if ( $width=="100%" ) { ? ? $width = $image_size[0]; ? } elseif ( $height=="100%" ) { ? ? $height = $image_size[1]; ? } elseif ( $width==0 ) { ? ? unset($width); ? } elseif ( $height==0 ) { ? ? unset($height); ? } ? $src=thumbimage(DIR_FS_CATALOG . '/' .$src, $width, $height, 1, 1, DIR_FS_CATALOG . '/' . DIR_WS_IMAGES . 'imagecache'); ? if ((($image_size[1]/$height) > ($image_size[0]/$width) ) && $height>0){ ? ? $width=ceil(($image_size[0]/$image_size[1])* $height); ? } elseif ($width>0) { ? ? $height=ceil($width/($image_size[0]/$image_size[1])); ? } ?} ? ?} ? ? ?} elseif (IMAGE_REQUIRED == 'false') { ? ? ? ?return ''; ? ? ?} // alt is added to the img tag even if it is null to prevent browsers from outputting // the image filename as default ? ?$image = '<img src="' . tep_output_string($src) . '" border="0" alt="' . tep_output_string($alt) . '"'; ? ?if (tep_not_null($alt)) { ? ? ?$image .= ' title=" ' . tep_output_string($alt) . ' "'; ? ?} ? ?if (tep_not_null($width) && tep_not_null($height)) { ? ? ?$image .= ' width="' . tep_output_string($width) . '" height="' . tep_output_string($height) . '"'; ? ?} ? ?if (tep_not_null($parameters)) $image .= ' ' . $parameters; ? ?$image .= '>'; ? ?return $image; ?} function thumbimage ($image, $x, $y, $aspectratio, $resize, $cachedir){ ? ? ? ? ?/*############################################## ? ? ? # ? ? ? ? ?- Thumbnail-Script v1.3 - ? ? ? ? ? # ? ? ? # Generating thumbnails 'on-the-fly' with PHP ?# ? ? ? # ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# ? ? ? # ?(c) by Christian Lamine, FlashDreams OHG ? ?# ? ? ? # ? ? ? ? ?http://www.flashdreams.de/ ? ? ? ? ?# ? ? ? # ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# ? ? ? # ? ? ? Modified by http://www.tse.at ? ? ? ? ?# ? ? ? # ? ? ? Modified by [email protected] ? ? ? ? ? ? ? # ? ? ? # ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# ? ? ? # This script may be freely used, distributed ?# ? ? ? # and modified without any charge as long as ? # ? ? ? # this copyright information is included. ? ? ?# ? ? ? # ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# ? ? ? # Any commercial selling of this script is ? ? # ? ? ? # forbidden. ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # ? ? ? # ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# ? ? ? # The author is not responsible for possible ? # ? ? ? # damage which may result from the application # ? ? ? # of this script, neither direct nor indirect. # ? ? ? # Use at your own risk! ? ? ? ? ? ? ? ? ? ? ? ?# ? ? ? ##############################################*/ ? ? error_reporting(0); ? ? $types = array (1 => "gif", "jpeg", "png", "swf", "psd", "wbmp"); ?$not_supported_formats = array ("GIF"); // Write in capital Letters!! ? ? umask(0); ? ? !is_dir ($cachedir) ? ? ? ? ? mkdir ($cachedir, 0777) ? ? ? ? : system ("chmod 0777 ".$cachedir); ? ? ? (!isset ($x) || ereg ('^[0-9]{1,}$', $x, $regs)) && ? ? ? (!isset ($y) || ereg ('^[0-9]{1,}$', $y, $regs)) && ? ? ? (isset ($x) || isset ($y)) ? ? ? ? ? ?? true ? ? ? ? ?: DIE ('Fehlende(r) oder ung?ltige(r) Gr??enparameter!'); ? ? !isset ($resize) || !ereg ('^[0|1]$', $resize, $regs) ? ? ? ? ?? $resize = 0 ? ? ? ? ?: $resize; ? ? !isset ($aspectratio) || !ereg ('^[0|1]$', $aspectratio, $regs) ? ? ? ? ?? isset ($x) && isset ($y) ? ? ? ? ? ? ? ? ? $aspectratio = 1 ? ? ? ? ? ? ? ? : $aspectratio = 0 ? ? ? ? ?: $aspectratio; ? ? !isset ($image) ? ? ? ? ?? DIE ('Es wurde kein Bild angegeben!') ? ? ? ? ?: !file_exists($image) ? ? ? ? ? ? ? ? DIE ('Die angegebene Datei konnte nicht auf dem Server gefunden werden!') ? ? ? ? ? ? ? : false; ? ? $imagedata = getimagesize($image); ? ? !$imagedata[2] || $imagedata[2] == 4 || $imagedata[2] == 5 ? ? ? ? ?? DIE ('Bei der angegebenen Datei handelt es sich nicht um ein Bild!') ? ? ? ? ?: false; ?$imgtype="!(ImageTypes() & IMG_" . strtoupper($types[$imagedata[2]]) . ")"; ? ? if ((eval($imgtype)) || (in_array(strtoupper(array_pop(explode('.', basename($image)))),$not_supported_formats))) { ? ? ?$image = substr ($image, (strrpos (DIR_FS_CATALOG . '/', '/'))+1); ? return $image; ? ? } ? ? if (!isset ($x)) $x = floor ($y * $imagedata[0] / $imagedata[1]); ? ? if (!isset ($y)) $y = floor ($x * $imagedata[1] / $imagedata[0]); ? ? if ($aspectratio && isset ($x) && isset ($y)) { ?if ((($imagedata[1]/$y) > ($imagedata[0]/$x) )){ ? ?$x=ceil(($imagedata[0]/$imagedata[1])* $y); ?} else { ? ?$y=ceil($x/($imagedata[0]/$imagedata[1])); ?} ? ? } ? ? $thumbfile = ?'/' . basename($image); ? ? if (file_exists ($cachedir.$thumbfile)) { ? ? ? ? ?$thumbdata = getimagesize ($cachedir.$thumbfile); ? ? ? ? ?$thumbdata[0] == $x && $thumbdata[1] == $y ? ? ? ? ? ? ? ? $iscached = true ? ? ? ? ? ? ? : $iscached = false; ? ? if (@filemtime($cachedir.$thumbfile) < @filemtime($image)) ?$iscached = false; ? ? } else { ? ? ? ? ?$iscached = false; ? ? } ? ? if (!$iscached) { ? ? ? ? ?($imagedata[0] > $x || $imagedata[1] > $y) || (($imagedata[0] < $x || $imagedata[1] < $y) && $resize) ? ? ? ? ? ? ? ? $makethumb = true ? ? ? ? ? ? ? : $makethumb = false; ? ? } else { ? ? ? ? ?$makethumb = false; ? ? } ? ? if ($makethumb) { ? ? ? ? ?$image = call_user_func("imagecreatefrom".$types[$imagedata[2]], $image); ? if (function_exists("imagecreatetruecolor") && ($thumb = imagecreatetruecolor ($x, $y))) { ?imagecopyresampled ($thumb, $image, 0, 0, 0, 0, $x, $y, $imagedata[0], $imagedata[1]); ? } else { ?$thumb = imagecreate ($x, $y); ?imagecopyresized ($thumb, $image, 0, 0, 0, 0, $x, $y, $imagedata[0], $imagedata[1]); ? } ? ? ? ? ?call_user_func("image".$types[$imagedata[2]], $thumb, $cachedir.$thumbfile); ? ? ? ? ?imagedestroy ($image); ? ? ? ? ?imagedestroy ($thumb); ? ? ? ? ?$image = DIR_WS_IMAGES . 'imagecache' . $thumbfile; ? ? } else { ? ? ? ? ?$iscached ? ? ? ? ? ? ? ? $image = DIR_WS_IMAGES . 'imagecache' . $thumbfile ? ? ? ? ? ? ? : $image = substr ($image, (strrpos (DIR_FS_CATALOG . '/', '/'))+1); ? ? } return $image; }
mpi-caraudio.nl Posted September 23, 2005 Author Posted September 23, 2005 ps. tried some changes in code of me own... didnt change thumb size... but scrambled the page in total. so some help with this code would be very nice ;)
Guest Posted September 23, 2005 Posted September 23, 2005 have you setup the admin->configuration->images to 150x150? Once you do that add a frame to see the resizing effect. Do you need to have a background margin to balance it? so if the image downsizes to 150x60 the top/bottom (90 pixels) can be filled with a separate background but I am not sure if it will look nice.
♥Vger Posted September 23, 2005 Posted September 23, 2005 As you've been editing code yourself you can't really expect people to know what you've done or what the solution is (and please don't post all your code changes). If this is the second thumbnailer that won't work maybe you'd better check to see if GD Library is installed (osC Admin --> Tools --> Server Info), because without it none of the thumbnailers will work. Vger
mpi-caraudio.nl Posted September 23, 2005 Author Posted September 23, 2005 okay.. maybe I have not been very clear about this. me sorry! 1. the code stated above is unchanged and the original code from the contribution. 2. image settings in my admin are: small image width: 150 small image height: 150 heading image width: 100 heading image height: 50 3. all my product images are edited by me and are all the same size 500x500... so no problem with aspect or things like that. 4. i changed the product_listing.php to make sure it got the image size for both width and height from the variable: HEADING_IMAGE_HEIGHT So in all product listings my images are 50 x 50 And in specials, bestsellers, product descriptions etc etc... images are displayed 150 x 150. 5. now this auto.thumb. contribution creates thumbs from the settings it first encounters. Resulting... some thubs are 50 x 50... some are 150 x 150. However in product description the thumb display is 150 x 150... where most thumbs created are 50 x 50 and will be stretched to 150 x 150.. which looks like crap. 6. so it would be nice if this code from this contribution used a predifined width and height (150 x 150) to create it's thumbs!
mpi-caraudio.nl Posted September 23, 2005 Author Posted September 23, 2005 Sorry about the code.. didn't see it was so much. :blush:
Guest Posted September 23, 2005 Posted September 23, 2005 The image you're using are jpeg right? Because gifs aint gonna work according to the contrib notes. I use the OTF gd and I dont have the problem you mentioned. Make sure the images are large enough for best results. Also when you change the admin parameters for image sizes make sure you delete the thumbnails previously generated. Better check it with the cache off (until it properly works).
mpi-caraudio.nl Posted September 23, 2005 Author Posted September 23, 2005 But thats not the problem.. The contribution works fine. It does what it says it does and quality is good. It even updates the thumbnails automatically when the original image has changed. I just need to make sure that this contribution only makes thumbnails of ONE size! Even when there are different sizes stated in the admin settings. Cause that's what I think it is doing; Creating thumbnails of the size in which you see them on the screen... but I want all thumbnails to be of a size I predifine... regardless of whats in the admin settings even. ...let me put it this way... Where does this piece of code fetch the size (width and height) to generate a thumbnail? Does it read the dimensions life from the online page ones you load it? (cause then I am in trouble and cant get this thing to do what I want) Or does it get the image size from the admin settings? (In that case I should also be able to tell the script/code that it should only fetch the size from: SMALL_IMAGE_HEIGHT and SMALL_IMAGE_WIDTH... right?)
Guest Posted September 23, 2005 Posted September 23, 2005 It does, it retrieves them from the admin. When the code (whichever code) calls the tep_image it passes the width/height parameters. Look the function definition and search the osc files you will see the parameters are passed in many cases (depends which module calls it) are SMALL_IMAGE_HEIGHT and SMALL_IMAGE_WIDTH. Your monitor screen res has nothing to do with it. This is where he gets the image dimensions from the file: if ($image_size = @getimagesize($src)) Now he has everything. The parameters passed specify the bounding box to put the image in. It shrinks the image while maintaining the aspect ratio placing it in the defined box.
mpi-caraudio.nl Posted September 24, 2005 Author Posted September 24, 2005 Of course my monitor or screen resolution has got nothing to do with it. I am using up to many words to explain this problem... Guess my English aint that good afterall :'( The thing is, my thumbnails are created in two different sizes. So I only want to tell this thumbnailer, it should only create thumbs of 150 x 150 pixels. But I guess that is not going to happen. So back to square-one... will try the newest contribution on thumbs or create the thumbs manualy. Anyway.. thank U for your time and input! (still thinking on that last post of you Enigma1... im guessing it says more than I understand right now)
♥Vger Posted September 24, 2005 Posted September 24, 2005 However in my settings I use 50 x 50 for product listing and 150 x 150 for everything else (made a small change to a PHP to support that of course). As Enigma pointed out, this programme takes the size of the thumb from the small image width and height in your osC admin panel. You have made changes to the code so that you have two different sizes of small images - but the thumbnail contribution will ony create thumbs in one size (according to small image width and height). I guess this is the answer you've been looking for. p.s. I don't think you'll find any other thumbnail contribution which will generate thumbs in two different size ranges. Vger
mpi-caraudio.nl Posted September 24, 2005 Author Posted September 24, 2005 As Enigma pointed out, this programme takes the size of the thumb from the small image width and height in your osC admin panel. If that was so, then I wouldnt have a problem, now would I! I wish it did exactly that!!! Vger... I am sorry... but I think you are assuming to much and reading to less. You have made changes to the code so that you have two different sizes of small images TRUE.. namely: I changed the product_listing.php to make sure it got the image size for both width and height from the variable: HEADING_IMAGE_HEIGHT So, changed one line: $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) To: $listing['products_name'], HEADING_IMAGE_HEIGHT, HEADING_IMAGE_HEIGHT) So, if all you are saying is correct, then I may assume that, that change has no influance on 'Automatic Thumbnailer' whatsoever! * So I can also conclude that the contribution doesnt take size from the variables (values set in admin) but life from the boxsize (the container in which the image is displayed) as the page loads when viewed by a user. So, it kinda takes it from the settings (variable-calls) stated within the product_listing.php... Which is NOT the same as taking it from the admin settings. Or I misunderstand you guys completly... And we are going about this the wrong way. The piece of code Enigma pointed out, only says that it gets the image size from the source (and thats not a call for a variable-value)... If I read that code correctly!? That would also support my point*! I dont want thumbs generated in two different size ranges... But that is what is happening. It's not a debat... Thats what it does! Just want it to STOP doing it!!! Trust me... It doesnt get the size from the variables... The entire code is ontop of this page... there is not one variable stated there... If it was I could easily change it. But that piece of code Enigma pointed out was the answer to my first question. Now I only need to insert variables in there. AND AGAIN I AM SORRY FOR THIS TOPIC... NORMALY I CAN BE SHORT AND TO THE POINT. I KNOW THIS ALL COULD BE CONFUSION TO YOU, BECAUSE I PROBABLY USE HTMLCODE-NAMES IN THE WRONG WAY (such as: Variable, Box, Call, Value... etc etc) BUT TRYING MY BEST HERE!
♥Vger Posted September 24, 2005 Posted September 24, 2005 What do I know? After all I only wrote the Thumbnail PDF Catalogue contribution - which is a merger of the Auto Thumbnail contribution and the PDF Catalog contribution. Vger
mpi-caraudio.nl Posted September 24, 2005 Author Posted September 24, 2005 Was I saying you dont know what you are talking about? If that is how I come across, then again my humble appologies sir. And lets not turn this forum into a log of personal issues... I am trying to solve a technical problem here. I also blamed myself in this topic to not being clear about this. So I am not blaming any of you.. In fact I have much respect and appriciation for the time and effort you people put in this. So dont take it personal when someone disagrees about a technical problem... I thought that's what forums are for.
Guest Posted September 24, 2005 Posted September 24, 2005 ok, see how the tep_image is called in this example: tep_image(DIR_WS_IMAGES . 'my_test_image.jpg', 'some name here', SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT); so the caller passes the dimensions of the bounding box. So the tep_image now has the real image dimensions (through the getimage function) plus the SMALL_IMAGE_WIDTH & SMALL_IMAGE_HEIGHT. It will attempt to shrink the full image to the SMALL_IMAGE_WIDTH & SMALL_IMAGE_HEIGHT by checking each parameter taking into account the aspect ratio. So for instance here is what I have in the code from otf contrib. (simplified & modified from the otf) function tep_image($src, $alt = '', $width = '', $height = '', $params = '', $bForce = false) { // initial code here ................................... $image_size = @getimagesize($src); $ratio = $image_size[1] / $image_size[0]; // Scale the image if not the original size if ($image_size[0] != $width || $image_size[1] != $height) { $rx = $image_size[0] / $width; $ry = $image_size[1] / $height; if ($rx < $ry) { $width = $height / $ratio; } else { $height = $width * $ratio; } // convert to int values & setup output img tag string ............. } So now take a full size image 640x480 And lets say the parameters passed for the bounding box where 100x100 so he gets the ratio of the width/height 640/100 = 6.4 480/100 = 4.8 ratio = 480/640 = 0.75 so now it calculates the new height (ry is less than rx) based on the height/ratio ie: 100*0.75 and so the box he builds is 100x75 as in this case will leave the width untouched so here is the bounding box I was refering to earlier.
mpi-caraudio.nl Posted September 26, 2005 Author Posted September 26, 2005 Yes... Thank you! :D I had to read it about three times... But with that information I changed the following: $src=thumbimage(DIR_FS_CATALOG . '/' .$src, $width, $height, 1, 1, DIR_FS_CATALOG . '/' . DIR_WS_IMAGES . 'imagecache'); Into: $src=thumbimage(DIR_FS_CATALOG . '/' .$src, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 1, 1, DIR_FS_CATALOG . '/' . DIR_WS_IMAGES . 'imagecache'); All works now for as far as I have tested it; The thumbs created are now all the same size even when image-boxes on the webpage aren't! I guess I should have just asked where the code 'wrote the thumbnail' (assuming that that is the part of the code that does that ;) ) Thank you both for you input :thumbsup:
Recommended Posts
Archived
This topic is now archived and is closed to further replies.