Jump to content

reduce image file size


Craig Hopson

Recommended Posts

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.

  • Like 1
Link to comment
Share on other sites

Guest So Called

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.

  • Like 1
Link to comment
Share on other sites

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

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

Guest So Called

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

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 by Craig Hopson
Link to comment
Share on other sites

you should have to use imagecreatetruecolor() instead of imagecreate().

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...