note 100185 modified in function.imagecreatefrompng by danbrown

From: Date: Thu, 30 Sep 2010 14:36:08 +0000
Subject: note 100185 modified in function.imagecreatefrompng by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-172844@lists.php.net to get a copy of this message
Hey, I just want to add for those of you who're having problem creating thumbs from png files - when you're using the "imagepng()" function put it in a variable. If you don't put it you'll probably be wondering why you're page will offer you to download itself rather than resizing it. Example: <?php public function resizeFile($fileInfo) { $image = $fileInfo['name']; $uploadedfile = $fileInfo['full']; if ($image) { $filename = stripslashes($fileInfo['name']); $extension = $fileInfo['ext']; $extension = strtolower($extension); $size = filesize($fileInfo['full']); if ($size > $this->maxSize * 1024) { die('You have exceeded the size limit!'); } $uploadedfile = $fileInfo['full']; $src = imagecreatefromstring($uploadedfile); list($width, $height) = getimagesize($uploadedfile); $newwidth = 130; $newheight = ($height / $width) * $newwidth; $tmp = imagecreatetruecolor($newwidth, $newheight); imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); $filenameThumb = "images/thumbs/" . $fileInfo['name']; if($extension == ("jpg" || "jpeg")) imagejpeg($tmp, $filenameThumb, 100); else if($extension == "png") // Disallow png display - this will create an image but won't display it! $tmpPng = imagePNG($tmp, $filenameThumb, 100); else imagegif($tmp, $filenameThumb, 100); imagedestroy($src); imagedestroy($tmp); } else { die("Fatal error."); } } ?> --was-- Hey, I just want to add for those of you who're having problem creating thumbs from png files - when you're using the "imagepng()" function put it in a variable. If you don't put it you'll probably be wondering why you're page will offer you to download itself rather than resizing it. Example: public function resizeFile($fileInfo) { $image = $fileInfo['name']; $uploadedfile = $fileInfo['full']; if ($image) { $filename = stripslashes($fileInfo['name']); $extension = $fileInfo['ext']; $extension = strtolower($extension); $size = filesize($fileInfo['full']); if ($size > $this->maxSize * 1024) { die('You have exceeded the size limit!'); } $uploadedfile = $fileInfo['full']; $src = imagecreatefromstring($uploadedfile); list($width, $height) = getimagesize($uploadedfile); $newwidth = 130; $newheight = ($height / $width) * $newwidth; $tmp = imagecreatetruecolor($newwidth, $newheight); imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); $filenameThumb = "images/thumbs/" . $fileInfo['name']; if($extension == ("jpg" || "jpeg")) imagejpeg($tmp, $filenameThumb, 100); else if($extension == "png") // Disallow png display - this will create an image but won't display it! $tmpPng = imagePNG($tmp, $filenameThumb, 100); else imagegif($tmp, $filenameThumb, 100); imagedestroy($src); imagedestroy($tmp); } else { die("Fatal error."); } } http://php.net/manual/en/function.imagecreatefrompng.php

« previous php.notes (#172844) next »