note 85152 added to function.imagecopyresized

From: Date: Mon, 18 Aug 2008 05:52:20 +0000
Subject: note 85152 added to function.imagecopyresized
Groups: php.notes 
Request: Send a blank email to php-notes+get-143577@lists.php.net to get a copy of this message
If the script should resize and save thumb I use this simple code: <? /** * Make thumbs from JPEG, PNG, GIF source file * * $tmpname = $_FILES['source']['tmp_name']; * $size - max width size * $save_dir - destination folder * $save_name - tnumb new name * * Author: LEDok - http://www.citadelavto.ru/ */ function img_resize( $tmpname, $size, $save_dir, $save_name ) { $save_dir .= ( substr($save_dir,-1) != "/") ? "/" : ""; $gis = GetImageSize($tmpname); $type = $gis[2]; switch($type) { case "1": $imorig = imagecreatefromgif($tmpname); break; case "2": $imorig = imagecreatefromjpeg($tmpname);break; case "3": $imorig = imagecreatefrompng($tmpname); break; default: $imorig = imagecreatefromjpeg($tmpname); } $x = imageSX($imorig); $y = imageSY($imorig); if($gis[0] <= $size) { $av = $x; $ah = $y; } else { $yc = $y*1.3333333; $d = $x>$yc?$x:$yc; $c = $d>$size ? $size/$d : $size; $av = $x*$c; //высота исходной картинки $ah = $y*$c; //длина исходной картинки } $im = imagecreate($av, $ah); $im = imagecreatetruecolor($av,$ah); if (imagecopyresampled($im,$imorig , 0,0,0,0,$av,$ah,$x,$y)) if (imagejpeg($im, $save_dir.$save_name)) return true; else return false; } ?> And now how using this function fast if ($_POST[pic]) { $tmpname = $_FILES['pic']['tmp_name']; @img_resize( $tmpname , 600 , "../album" , "album_".$id.".jpg"); @img_resize( $tmpname , 120 , "../album" , "album_".$id."_small.jpg"); @img_resize( $tmpname , 60 , "../album" , "album_".$id."verysmall.jpg"); } else echo "No Images uploaded via POST"; ?> ---- Server IP: 193.233.48.78 (proxied: 193.233.51.120) Probable Submitter: 88.205.187.9 ---- Manual Page -- http://www.php.net/manual/en/function.imagecopyresized.php Edit -- https://master.php.net/note/edit/85152 Del: integrated -- https://master.php.net/note/delete/85152/integrated Del: useless -- https://master.php.net/note/delete/85152/useless Del: bad code -- https://master.php.net/note/delete/85152/bad+code Del: spam -- https://master.php.net/note/delete/85152/spam Del: non-english -- https://master.php.net/note/delete/85152/non-english Del: in docs -- https://master.php.net/note/delete/85152/in+docs Del: other reasons-- https://master.php.net/note/delete/85152 Reject -- https://master.php.net/note/reject/85152 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#143577) next »