Jump to content

generating thumbnails


RobertP

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.