Jump to content

[SOLVED] thumbnail creation script help


thewooleymammoth

Recommended Posts

im trying to adapt a tutorial to work for my site from

 

http://www.4wordsystems.com/php_image_resize.php

 

i want to make a page that checks all the images in all my folders and checks to see if they have a thumbnail, if not then make one, however i cant figure out what im not doing right to make this work, on my wamp server i keep getting errors, here is my changed code

 

<?php 
include ('menu.php');
$dir=array('bikinis', 'clothes', 'comics', 'gif', 'images', 'movieposters', 'nature', 'pics', 'signs', 'textures', 'walls');

foreach($dir as $d)
              {
               $img=scandir("$d");
               foreach($img as $i)
                           {
                           $type=explode(".", $i);
                           if ($type[1] != 'gif' && !file_exists("/$d/$i") && $i != '.' && $i !='..')
                              {
                              echo
                               //createThumbnail("$d", "$i", "$d/thumbs", 400);
                               // Capture the original size of the uploaded image
                                list($width,$height)=getimagesize("$d/$i");

                               // For our purposes, I have resized the image to be
                               // 600 pixels wide, and maintain the original aspect
                               // ratio. This prevents the image from being "stretched"
                               // or "squashed". If you prefer some max width other than
                               // 600, simply change the $newwidth variable
                               $newwidth=400;
                               $newheight=($height/$width)*400;
                               $tmp=imagecreatetruecolor($newwidth,$newheight);

                               // this line actually does the image resizing, copying from the original
                               // image into the $tmp image
                               imagecopyresampled($tmp,"/$d/$i",0,0,0,0,$newwidth,$newheight,$width,$height);

                               // now write the resized image to disk. I have assumed that you want the
                               // resized, uploaded image file to reside in the ./images subdirectory.
                               $filename = "$d/thumbs/$i";
                               imagejpeg($tmp,$filename,100);

                               imagedestroy($src);
                               imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when the request
                               // has completed.
                               echo "<BR> thumbnail created for $d/$i in $d/thumbs";
                               }
                           else if ($type[1] == 'gif')
                                {
                                 copy("/$d/$i", "/$d/thumbs/$i");
                                }else {}
                           }

              }
include('end.php');
?>

 

and i get these error codes

 

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in C:\wamp\www\image site\thumbs.php on line 33

Warning: imagedestroy(): supplied argument is not a valid Image resource in C:\wamp\www\image site\thumbs.php on line 40

thumbnail created for bikinis/00000059.jpg in bikinis/thumbsArray
Warning: imagecopyresampled(): supplied argument is not a valid Image resource in C:\wamp\www\image site\thumbs.php on line 33

Warning: imagedestroy(): supplied argument is not a valid Image resource in C:\wamp\www\image site\thumbs.php on line 40

 

im stumped :(

Link to comment
Share on other sites

figured it out thanks for the help that manual link helped, here is the code that worked incase there are future people with this problem

 

//Thumbnail creation page
include ('menu.php');
echo "<div class='arcticle'>";
//$dir is path to images
$dir=array('bikinis', 'clothes', 'comics', 'gif', 'movieposters', 'nature', 'pics', 'signs', 'textures', 'walls');

foreach($dir as $d)
              {
               $img=scandir("$d");
               foreach($img as $i)
                           {
                           $type=explode(".", $i);
                           if ($type[1] != 'gif' && !file_exists("$d/thumbs/$i") && $i != '.' && $i !='..' && file_exists("$d/$i") && filesize("$d/$i") >100 && $i !='thumbs.db' && $i !='Thumbs.db')
                              {
                               //createThumbnail("$d", "$i", "$d/thumbs", 400);
                               // Capture the original size of the uploaded image
                                list($width,$height)=getimagesize("$d/$i");

                               // For our purposes, I have resized the image to be
                               // 600 pixels wide, and maintain the original aspect
                               // ratio. This prevents the image from being "stretched"
                               // or "squashed". If you prefer some max width other than
                               // 600, simply change the $newwidth variable
                               $newwidth=400;
                               $newheight=($height/$width)*400;
                               $image = imagecreatefromjpeg("$d/$i");
                               $tmp=imagecreatetruecolor($newwidth,$newheight);

                               // this line actually does the image resizing, copying from the original
                               // image into the $tmp image
                               imagecopyresampled($tmp,$image,0,0,0,0,$newwidth,$newheight,$width,$height);

                               // now write the resized image to disk. I have assumed that you want the
                               // resized, uploaded image file to reside in the ./images subdirectory.
                               $filename = "$d/thumbs/$i";
                               imagejpeg($tmp,$filename,100);

                               imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when the request
                               // has completed.
                               echo "<BR> thumbnail created for $d/$i in $d/thumbs<BR>";
                               }
                           else if ($type[1] == 'gif' && !file_exists("$d/thumbs/$i"))
                                {
                                 copy("$d/$i", "$d/thumbs/$i");
                                 echo "<BR>$i was copied to $d/thumbs/$i";
                                }else {}

                           }
                             echo "<BR><b> $d Operation completed!</b>";

              }

include('end.php');
?>

Link to comment
Share on other sites

anyone know why this would work on my computer with wamp but not on my server?

 

i get a regular output like i would expect on localhost/thumbs.php but not on

http://fatalinjury.org/thumbs.php

 

i just get blank... it worked for a while, is it possible my host doesnt like how much recourses the page takes up or anything like that?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.