hasini Posted February 5, 2009 Share Posted February 5, 2009 Hi Please help me I'm unable to create Thumnail for Images greater than 1.3 MB with dimensions 1990px width and 2200px height please help me anyone.....................please Quote Link to comment https://forums.phpfreaks.com/topic/143892-thumbnail-generator/ Share on other sites More sharing options...
sKunKbad Posted February 5, 2009 Share Posted February 5, 2009 post some code Quote Link to comment https://forums.phpfreaks.com/topic/143892-thumbnail-generator/#findComment-755033 Share on other sites More sharing options...
The Little Guy Posted February 5, 2009 Share Posted February 5, 2009 This should do the trick: http://phpsnips.com/snippet.php?id=5 Quote Link to comment https://forums.phpfreaks.com/topic/143892-thumbnail-generator/#findComment-755034 Share on other sites More sharing options...
sKunKbad Posted February 5, 2009 Share Posted February 5, 2009 This is the thumbnail generator class (ThumbnailImage.php) that I use: <?php //requires GD 2.0.1 or higher //note about gif class ThumbnailImage{ private $image; //not applicable to gif or png private $quality = 100; private $mimetype; private $imageproperties; private $initialfilesize; //////////////////////////////////////////////////////// //constructor //////////////////////////////////////////////////////// public function __construct($file, $thumbnailsize = 100){ //check path is_file($file) or die ("File: $file doesn't exist."); $this->initialfilesize = filesize($file); $this->imageproperties = getimagesize($file) or die ("Incorrect file type."); // new function image_type_to_mime_type $this->mimetype = image_type_to_mime_type($this->imageproperties[2]); //create image switch($this->imageproperties[2]){ case IMAGETYPE_JPEG: $this->image = imagecreatefromjpeg($file); break; case IMAGETYPE_GIF: $this->image = imagecreatefromgif($file); break; case IMAGETYPE_PNG: $this->image = imagecreatefrompng($file); break; default: die("Couldn't create image."); } $this->createThumb($thumbnailsize); } //////////////////////////////////////////////////////// //destructor //////////////////////////////////////////////////////// public function __destruct(){ if(isset($this->image)){ imagedestroy($this->image); } } //////////////////////////////////////////////////////// //public methods //////////////////////////////////////////////////////// public function getImage(){ header("Content-type: $this->mimetype"); switch($this->imageproperties[2]){ case IMAGETYPE_JPEG: imagejpeg($this->image,"",$this->quality); break; case IMAGETYPE_GIF: imagegif($this->image); break; case IMAGETYPE_PNG: imagepng($this->image); break; default: die("Couldn't create image."); } } //////////////////////////////////////////////////////// public function getMimeType(){ return $this->mimetype; } //////////////////////////////////////////////////////// public function getQuality(){ $quality = null; if($this->imageproperties[2] == IMAGETYPE_JPEG){ $quality = $this->quality; } return $quality; } //////////////////////////////////////////////////////// public function setQuality($quality){ if($quality > 100 || $quality < 1){ $quality = 75; } if($this->imageproperties[2] == IMAGETYPE_JPEG){ $this->quality = $quality; } } //////////////////////////////////////////////////////// public function getInitialFileSize(){ return $this->initialfilesize; } //////////////////////////////////////////////////////// //private methods //////////////////////////////////////////////////////// private function createThumb($thumbnailsize){ //array elements $srcW = $this->imageproperties[0]; $srcH = $this->imageproperties[1]; //only adjust if larger than reduction size if($srcW >$thumbnailsize || $srcH > $thumbnailsize){ $reduction = $this->calculateReduction($thumbnailsize); //get proportions $desW = $srcW/$reduction; $desH = $srcH/$reduction; $copy = imagecreatetruecolor($desW, $desH); imagecopyresampled($copy,$this->image,0,0,0,0,$desW, $desH, $srcW, $srcH) or die ("Image copy failed."); //destroy original imagedestroy($this->image); $this->image = $copy; } } //////////////////////////////////////////////////////// private function calculateReduction($thumbnailsize){ //adjust $srcW = $this->imageproperties[0]; $srcH = $this->imageproperties[1]; if($srcW < $srcH){ $reduction = round($srcH/$thumbnailsize); }else{ $reduction = round($srcW/$thumbnailsize); } return $reduction; } }//end class //////////////////////////////////////////////////////// ?> This is the file (getthumb.php) called by the source of the img tag: <?php //this file will be the src for an img tag require 'ThumbnailImage.php'; $path = @$_GET["path"]; $maxsize = @$_GET["size"]; if(!isset($maxsize)){ $maxsize=100; } if(isset($path)){ $thumb = new ThumbNailImage($path, $maxsize); $thumb->getImage(); } ?> Usage: <img src="getthumb.php?path=../big_pics/Access_road_n_mountains.jpg&size=256" alt= "Access road n mountains" /> Give it a try. Quote Link to comment https://forums.phpfreaks.com/topic/143892-thumbnail-generator/#findComment-755037 Share on other sites More sharing options...
hasini Posted February 5, 2009 Author Share Posted February 5, 2009 tried your code but not working Quote Link to comment https://forums.phpfreaks.com/topic/143892-thumbnail-generator/#findComment-755045 Share on other sites More sharing options...
sKunKbad Posted February 5, 2009 Share Posted February 5, 2009 tried your code but not working You have to have GD 2.0.1 or higher installed, and this only works on php5. I probably should have mentioned that earlier. Quote Link to comment https://forums.phpfreaks.com/topic/143892-thumbnail-generator/#findComment-755084 Share on other sites More sharing options...
xylex Posted February 5, 2009 Share Posted February 5, 2009 Have you checked your memory_limit, upload_max_filesize and post_max_size settings to make sure you're not hitting something there? Quote Link to comment https://forums.phpfreaks.com/topic/143892-thumbnail-generator/#findComment-755339 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.