note 50399 added to function.imagecopyresized
| From: | haker4o at haker4o dot org | Date: | Sun, 27 Feb 2005 04:57:20 +0000 |
| Subject: | note 50399 added to function.imagecopyresized | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-85621@lists.php.net to get a copy of this message | ||
<?php
// Resize image.
// Writeen By: Smelban & Haker4o
// Mails smelban@smwebdesigns.com & Haker4o@Haker4o.org
// This code is written to only execute on jpg,gif,png
// $picname = resizepics('pics', 'new widthmax', 'new heightmax');
// Demo $picname = resizepics('stihche.jpg', '180', '140');
$picname = resizepics('picture-name.format', '180', '140');
echo $pickname;
//Error
die( "<font color=\"#FF0066\"><center><b>File not exists
:(<b></center></FONT>");
//Funcion resizepics
function resizepics($pics, $newwidth, $newheight){
if(preg_match("/.jpg/i", "$pics")){
header('Content-type: image/jpeg');
}
if (preg_match("/.gif/i", "$pics")){
header('Content-type: image/gif');
}
list($width, $height) = getimagesize($pics);
if($width > $height && $newheight < $height){
$newheight = $height / ($width / $newwidth);
} else if ($width < $height && $newwidth < $width) {
$newwidth = $width / ($height / $newheight);
} else {
$newwidth = $width;
$newheight = $height;
}
if(preg_match("/.jpg/i", "$pics")){
$source = imagecreatefromjpeg($pics);
}
if(preg_match("/.jpeg/i", "$pics")){
$source = imagecreatefromjpeg($pics);
}
if(preg_match("/.jpeg/i", "$pics")){
$source = Imagecreatefromjpeg($pics);
}
if(preg_match("/.png/i", "$pics")){
$source = imagecreatefrompng($pics);
}
if(preg_match("/.gif/i", "$pics")){
$source = imagecreatefromgif($pics);
}
$thumb = imagecreatetruecolor($newwidth, $newheight);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
return imagejpeg($thumb);
if(preg_match("/.jpg/i", "$pics")){
return imagejpeg($thumb);
}
if(preg_match("/.jpeg/i", "$pics")){
return imagejpeg($thumb);
}
if(preg_match("/.jpeg/i", "$pics")){
return imagejpeg($thumb);
}
if(preg_match("/.png/i", "$pics")){
return imagepng($thumb);
}
if(preg_match("/.gif/i", "$pics")){
return imagegif($thumb);
}
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.imagecopyresized.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50399
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50399&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50399&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50399&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50399&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50399&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50399&report=yes
Search -- http://master.php.net/manage/user-notes.php