note 88533 added to function.imagecopyresized
| From: | davidfromquidware at osu1 dot php dot net | Date: | Wed, 28 Jan 2009 08:50:14 +0000 |
| Subject: | note 88533 added to function.imagecopyresized | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-149880@lists.php.net to get a copy of this message | ||
If the script should resize and save thumb I use this simple code, I made a couple corrections from
last one and added the possibility to resize to a max HEIGHT:
<?php
/**
* 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
* $maxisheight - is max for width (if not is for height)
*
* Author: David Taubmann http://www.quidware.com (edited
from LEDok - http://www.citadelavto.ru/)
*/
/*/ // 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."_maxheight.jpg", 1);
}
else
echo "No Images uploaded via POST";
/**/
function img_resize( $tmpname, $size, $save_dir, $save_name, $maxisheight = 0 )
{
$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);
$woh = (!$maxisheight)? $gis[0] : $gis[1] ;
if($woh <= $size)
{
$aw = $x;
$ah = $y;
}
else
{
if(!$maxisheight){
$aw = $size;
$ah = $size * $y / $x;
} else {
$aw = $size * $x / $y;
$ah = $size;
}
}
$im = imagecreatetruecolor($aw,$ah);
if (imagecopyresampled($im,$imorig , 0,0,0,0,$aw,$ah,$x,$y))
if (imagejpeg($im, $save_dir.$save_name))
return true;
else
return false;
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 189.163.161.72
----
Manual Page -- http://www.php.net/manual/en/function.imagecopyresized.php
Edit -- https://master.php.net/note/edit/88533
Del: integrated -- https://master.php.net/note/delete/88533/integrated
Del: useless -- https://master.php.net/note/delete/88533/useless
Del: bad code -- https://master.php.net/note/delete/88533/bad+code
Del: spam -- https://master.php.net/note/delete/88533/spam
Del: non-english -- https://master.php.net/note/delete/88533/non-english
Del: in docs -- https://master.php.net/note/delete/88533/in+docs
Del: other reasons-- https://master.php.net/note/delete/88533
Reject -- https://master.php.net/note/reject/88533
Search -- https://master.php.net/manage/user-notes.php