justsomeguy Posted June 14, 2012 Share Posted June 14, 2012 No, like the thumbnail.php file used in the img tag earlier. That file would check if the thumbnail already exists and either use it or create it. So it would create the thumbnail the first time it is requested and use the existing one after that. One benefit there is that you can always delete all of the thumbnail if you want to recreate them at a different size or format or whatever. 1 Link to comment Share on other sites More sharing options...
Craig Hopson Posted June 14, 2012 Author Share Posted June 14, 2012 Like this imagejpeg($dst_img, 'uploads/'.$_COOKIE['id'].'/thumbnail/'.$ONLYname,100); Link to comment Share on other sites More sharing options...
Guest So Called Posted June 14, 2012 Share Posted June 14, 2012 Just write a PHP script that reads all your images, reduces them, and saves the reduced images. You can use PHP to get a directory listing of your image directory, then step through it image by image and check if there's a thumbnail. Any that don't have thumbnails would be created and saved. For example if you have filename.jpg it would check for filename_th.jpg, and create one if it doesn't exist. You can run the script whenever you add new images. 1 Link to comment Share on other sites More sharing options...
birbal Posted June 14, 2012 Share Posted June 14, 2012 Seems to be working ok only problem is the thumbnails are VERY poor quality any ideas??posting the original image with that one would be more helpful. though you should use imagecropresampled() rather than imagecopyresized(). imagecopyresized() deform when it crop which could make image defective. Link to comment Share on other sites More sharing options...
Craig Hopson Posted June 15, 2012 Author Share Posted June 15, 2012 posting the original image with that one would be more helpful. though you should use imagecropresampled() rather than imagecopyresized(). imagecopyresized() deform when it crop which could make image defective.i have done this but still the same any other ideas?? Link to comment Share on other sites More sharing options...
Guest So Called Posted June 15, 2012 Share Posted June 15, 2012 If that's your image then it's all washed out with little contrast. IMO that's not a usable image. Back lighting overwhelmed the foreground. I doubt that image could ever be fixed. Link to comment Share on other sites More sharing options...
Craig Hopson Posted June 15, 2012 Author Share Posted June 15, 2012 ok this is original imageAnd this is after now this is not a usable thumbnail what am i doing wrong? Link to comment Share on other sites More sharing options...
justsomeguy Posted June 15, 2012 Share Posted June 15, 2012 Are you using the code in post 22? If not, post what you're using. I don't really like how that function will re-save a jpg image, and it also won't define $NewName if the image is a jpg. Link to comment Share on other sites More sharing options...
Craig Hopson Posted June 15, 2012 Author Share Posted June 15, 2012 Yes I have sorted that out the only problem is the thumbnail quality Link to comment Share on other sites More sharing options...
Guest So Called Posted June 15, 2012 Share Posted June 15, 2012 So post the code that creates it. Link to comment Share on other sites More sharing options...
justsomeguy Posted June 15, 2012 Share Posted June 15, 2012 If the code that you're using is different than the code in post 22 then please post the updated code. Link to comment Share on other sites More sharing options...
Craig Hopson Posted June 15, 2012 Author Share Posted June 15, 2012 (edited) function converttojpg($originalimg){$filetype = @end(explode(".", $originalimg));if (strtolower($filetype) == 'jpg' or strtolower($filetype) == 'jpeg') { $srcImg = imagecreatefromjpeg($originalimg); imagejpeg($srcImg,$originalimg,75); imagedestroy($srcImg); $thumb_img = imagecreatefromjpeg($originalimg); $origw=imagesx($thumb_img);$origh=imagesy($thumb_img);$new_w = 150;$diff=$origw/$new_w;$new_h=$new_w;$dst_img = imagecreate($new_w,$new_h);imagecopyresampled($dst_img,$thumb_img,0,0,0,0,$new_w,$new_h,imagesx($thumb_img),imagesy($thumb_img));$ONLYname = str_replace('uploads/'.$_COOKIE['id'].'/',"",$originalimg);imagejpeg($dst_img, 'uploads/'.$_COOKIE['id'].'/thumbnail/'.$ONLYname,100); } if (strtolower($filetype) == 'png') { $srcImg = imagecreatefrompng($originalimg); imagejpeg($srcImg,$originalimg,100); imagedestroy($srcImg); $NewName = str_replace(".png",".jpg",$originalimg); rename($originalimg,$NewName); $thumb_img = imagecreatefromjpeg($NewName); $origw=imagesx($thumb_img);$origh=imagesy($thumb_img);$new_w = 150;$diff=$origw/$new_w;$new_h=$new_w;$dst_img = imagecreate($new_w,$new_h);imagecopyresampled($dst_img,$thumb_img,0,0,0,0,$new_w,$new_h,imagesx($thumb_img),imagesy($thumb_img));$ONLYname = str_replace('uploads/'.$_COOKIE['id'].'/',"",$NewName);imagejpeg($dst_img, 'uploads/'.$_COOKIE['id'].'/thumbnail/'.$ONLYname,100); } if (strtolower($filetype) == 'gif') { $srcImg = imagecreatefromgif($originalimg); imagejpeg($srcImg,$originalimg,100); imagedestroy($srcImg); $NewName = str_replace(".gif",".jpg",$originalimg); rename($originalimg,$NewName);$thumb_img = imagecreatefromjpeg($NewName); $origw=imagesx($thumb_img);$origh=imagesy($thumb_img);$new_w = 150;$diff=$origw/$new_w;$new_h=$new_w;$dst_img = imagecreate($new_w,$new_h);imagecopyresampled($dst_img,$thumb_img,0,0,0,0,$new_w,$new_h,imagesx($thumb_img),imagesy($thumb_img));$ONLYname = str_replace('uploads/'.$_COOKIE['id'].'/',"",$NewName);imagejpeg($dst_img, 'uploads/'.$_COOKIE['id'].'/thumbnail/'.$ONLYname,100); } } Thanks guys for taking the time to look into this for me Edited June 15, 2012 by Craig Hopson Link to comment Share on other sites More sharing options...
birbal Posted June 15, 2012 Share Posted June 15, 2012 you should have to use imagecreatetruecolor() instead of imagecreate(). Link to comment Share on other sites More sharing options...
Craig Hopson Posted June 15, 2012 Author Share Posted June 15, 2012 you should have to use imagecreatetruecolor() instead of imagecreate().PROBLEM SOLVED THANKS BIRBAL YOU REALLY ARE THE MAN Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now