Jump to content

Recommended Posts

i have a few questions about generating thumbnails.

 

1. is it best to retain image quality/resolution by using a ratio for shrinking the width/height? example below

2. once i generate a thumbnail, does it make sense to store it on the server for access later?

 

ratio example

	public static function generateThumbnail($file){
	$w = 80;//80px width, height is relative
	header('Content-type: image/jpeg');
	list($width,$height) = getimagesize($file);
	$ratio = $w/$width;
	$new_height = $height*$ratio;
	$image_p = imagecreatetruecolor($w,$new_height);
	$image = imagecreatefromjpeg($file);
	imagecopyresampled($image_p,$image,0,0,0,0,$w,$new_height,$width,$height);
	imagejpeg($image_p,null,100);
}

 

also, i store all my files outside of the web root, and access each one via a php script for downloading / viewing. i do this for security. some files are not blocked to normal members, and others blocked to guests. is this the best way for that?

Link to comment
https://forums.phpfreaks.com/topic/256998-generating-thumbnails/
Share on other sites

1. Usually it's best to either crop or resize while maintaining aspect ratios. Otherwise, it's just going to look bad if you do a substantial resize.

 

2. Yes, it makes sense to store it on the server because generally image manipulations are costly. The less you need to do them the better.

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.