I'm successfully making thumbnails on the fly with this ultimate statement:
imagejpeg($image_resized, '', 80);

Now I want to save the file, which is the 2nd parameter. I can output and save at the same time right? The php manual says OR, but maybe that's not correct.

Anyway, i've tried a few things.
imagejpeg($image_resized, 'pics/$dir/thumbs/$image_resized', 80);
imagejpeg($image_resized, 'pics/$dir/thumbs/$filename', 80);

Now matter what I put as the 2nd parm It kills the dynamic thumbnailing (doesn't display the pic anymore), and it doesn't save the file.

I get no errors... just doesn't work.

    Hi,

    In the path, you're embedding a variable in a single-quoted string.

    Either change to double-quotes (quicker but horrible to debug as you've just found out) ...

    <?php
    imagejpeg($image_resized, "pics/$dir/thumbs/$image_resized", 80);
    ?>

    ... or use concatenation (my preferred way) ...

    <?php
    imagejpeg($image_resized, 'pics/'.$dir.'/thumbs/'.$image_resized, 80);
    ?>

    Paul.

      thanks paul,.. it's still not rendering the thumbs, but I know the path parm is correct cause it creates a file called "Resource id #3" in there. It creates the thumbnails fine without that parm.

        you know what's really unfortunate... In firefox it caches the thumbnails. So for example, if I click one of the pics to view it, and then go back to the thumbnails, you don't have to wait for it to reload. In IE it reloads them everytime. The only reason i want to save the thumbs is so I can use them the 2 time around to make the loading quicker. I wouldn't have to do this at all if IE also cached. Arrrg!

          anyone??? current problem, when I put in the destination param, it breaks the thumbnails and only saves a file called Resource ID #3 in the destination folder. So the folder is correct. It outputs the thumbs to the screen fine without this param. As soon as i put it in, it breaks the outputting to screen and only saves 1 file called Resource ID #3 in the destination folder.

            The image is only output if the 2nd argument is omitted or is NULL. You may have to call it twice: once with the file argument and once with it omitted or set to NULL (the latter if you want to use the 3rd argument).

              thanks... I guess that 'OR' in the manual is correct

                ok, so that explains why it doesn't output to screen. But it should still save the file as a jpeg instead of Resource ID #3

                header('Content-type: image/jpeg');
                foreach($_GET AS $key => $value) {  ${$key} = $value; } 
                
                $percent = .08;
                $filename = stripslashes($filename);
                
                $imageInfo = @getimagesize("pics/$dir/$filename"); 
                $width = $imageInfo[0]; 
                $height = $imageInfo[1]; 
                $new_width = 50;
                $new_height = 50;
                
                
                $image_resized = imagecreatetruecolor($new_width, $new_height);
                $image = imagecreatefromjpeg("pics/$dir/$filename");
                imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
                imagejpeg($image_resized, "pics/$dir/thumbs/$image_resized", 80);
                //imagejpeg($image_resized, "null", 80);
                imagedestroy($image_resized);
                
                
                  [color=red]$image_resized[/color] = imagecreatetruecolor($new_width, $new_height);
                  $image = imagecreatefromjpeg("pics/$dir/$filename");
                  imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
                  imagejpeg($image_resized, "pics/$dir/thumbs/[color=red]$image_resized[/color]", 80);
                  

                  imagecreatetruecolor() returns an image resource ID, not a file name. You'll need to either hard-code an file name or come up with some other logic/algorithm to generate the file name.

                    Write a Reply...