note 55743 added to function.imagecopyresized
| From: | MaLaZ at osu1 dot php dot net | Date: | Fri, 12 Aug 2005 02:24:33 +0000 |
| Subject: | note 55743 added to function.imagecopyresized | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-93475@lists.php.net to get a copy of this message | ||
simple script for creating thumbnails with process information and saving original ratio thumbnail
to new destination...good then useing with upload or uploaded images:
<?php
//Upload------------------------------------
if(isset( $submit ))
{
if ($_FILES['imagefile']['type'] == "image/jpeg"){
copy ($_FILES['imagefile']['tmp_name'],
"../images/".$_FILES['imagefile']['name'])
or die ("Could not copy");
echo "";
echo "Image Name: ".$_FILES['imagefile']['name']."";
echo "<br>Image Size:
".$_FILES['imagefile']['size']."";
echo "<br>Image Type:
".$_FILES['imagefile']['type']."";
echo "<br>Image Copy Done....<br>";
}
else {
echo "<br><br>";
echo "bad file type
(".$_FILES['imagefile']['name'].")<br>";exit;
}
//-----upload end
//------start thumbnailer
$thumbsize=120;
echo "Thumbnail Info: <br>
1.Thumb defined size: - OK: $thumbsize<br>";
$imgfile = "../images/$imagefile_name";//processed image
echo "
2.Image destination: - OK: $imgfile<br>";
header('Content-type: image/jpeg');
list($width, $height) = getimagesize($imgfile);
echo "3.Image size - OK: W=$width x H=$height<br>";
$imgratio=$width/$height;
echo "3.Image ratio - OK: $imgratio<br>";
if ($imgratio>1){
$newwidth = $thumbsize;
$newheight = $thumbsize/$imgratio;}
else{
$newheight = $thumbsize;
$newwidth = $thumbsize*$imgratio;}
echo "4.Thumb new size -OK: W=$newwidth x H=$newheight<br>";
$thumb = ImageCreateTrueColor($newwidth,$newheight);
echo "5.TrueColor - OK<br>";
$source = imagecreatefromjpeg($imgfile);
echo "6.From JPG - OK<br>";
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($thumb,"../images/thumbs/thumb_$imagefile_name",100);echo "7.Done... -
OK<br>";
//-----------end--------------
?>
or without any info, just resizing:
<?php
//------start thumbnailer
$thumbsize=120;
$imgfile = "../images/$imagefile_name";
header('Content-type: image/jpeg');
list($width, $height) = getimagesize($imgfile);
$imgratio=$width/$height;
if ($imgratio>1){
$newwidth = $thumbsize;
$newheight = $thumbsize/$imgratio;}
else{
$newheight = $thumbsize;
$newwidth = $thumbsize*$imgratio;}
$thumb = ImageCreateTrueColor($newwidth,$newheight);
$source = imagecreatefromjpeg($imgfile);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($thumb,"../images/thumbs/thumb_$imagefile_name",100);
//-----------end--------------
?>
i hope it helps.
----
Manual Page -- http://www.php.net/manual/en/function.imagecopyresized.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+55743
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55743&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55743&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55743&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55743&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55743&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55743&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+55743&report=yes
Search -- http://master.php.net/manage/user-notes.php