note 91117 added to function.imagecopyresized
| From: | akbittu at gmail dot com | Date: | Tue, 26 May 2009 06:39:29 +0000 |
| Subject: | note 91117 added to function.imagecopyresized | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-156013@lists.php.net to get a copy of this message | ||
<?php
/*
Image Resizer v 1.0.0
Copyright (c) 2008, 2009 Abhishek Kumar.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
Feature:-
* Resize images in batch.
* Customize resizing dimensions.
* Maintain aspect ratio.
Steps to use this script :-
* Step-1: Create a folder and name it 'Container'.
* Step-2: Put all the images in this folder that you want to resize.
* Step-3: Run the script to resize those images.
*/
echo '<b>Image Resizer v 1.0.0 </b><br><br>';
ImageResizingDirectory("./Container");
function ImageResizingDirectory($iFolder)
{
if ($DirectoryHandle = opendir($iFolder))
{
while (false !== ($Entry = readdir($DirectoryHandle)))
{
if ($Entry != '.' && $Entry != '..')
{
$FilePath = ltrim($iFolder.'/'.$Entry, './');
DisplayStatus('S001', $FilePath);
/*
Argument definition of ImageResizer:
* Argument-1: Image-File-Path,
* Argument-2: Image-Resizing-Width,
* Argument-3: Image-Resizing-Height.
**/
ImageResizer($FilePath, 160, 120);
//
DisplayStatus('S002', $FilePath);
}
}
closedir();
}
}
function DisplayStatus($iMsgId, $iMsgArg)
{
switch($iMsgId)
{
case 'S001': echo str_replace("[Content]", 'Processing image at
<i>'.$iMsgArg.'</i>.', "[Content]<br>");
break;
case 'S002': echo str_replace("[Content]", 'Image at
<i>'.$iMsgArg.'</i> is resized.', "[Content]<br>");
break;
default: echo '<br>';
}
}
function ImageResizer($ImageLocation, $ImageResizingWidth, $ImageResizingHeight)
{
list($PictureWidth, $PictureHeight) = getimagesize($ImageLocation);
$PictureAspectRatio = $PictureWidth/$PictureHeight;
$Width = $ImageResizingWidth;
$Height = $ImageResizingHeight;
$AspectRatio = $Width/$Height;
if ($PictureAspectRatio > $AspectRatio)
{
$NewWidth = $Width;
$NewHeight = $Width/$PictureWidth * $PictureHeight;
}
else if ($PictureAspectRatio < $AspectRatio)
{
$NewWidth = $Height/$PictureHeight * $PictureWidth;
$NewHeight = $Height;
}
else if ($PictureAspectRatio == $AspectRatio)
{
$NewWidth = $Width;
$NewHeight = $Height;
}
$thumb = imagecreatetruecolor($NewWidth, $NewHeight);
$source = imagecreatefromjpeg($ImageLocation);
imagecopyresized($thumb, $source, 0,0,0,0, $NewWidth, $NewHeight, $PictureWidth, $PictureHeight);
imagejpeg($thumb, $ImageLocation, 50);
imagedestroy($thumb);
imagedestroy($source);
}
?>
----
Server IP: 59.162.86.8
Probable Submitter: 122.160.132.198
----
Manual Page -- http://www.php.net/manual/en/function.imagecopyresized.php
Edit -- https://master.php.net/note/edit/91117
Del: integrated -- https://master.php.net/note/delete/91117/integrated
Del: useless -- https://master.php.net/note/delete/91117/useless
Del: bad code -- https://master.php.net/note/delete/91117/bad+code
Del: spam -- https://master.php.net/note/delete/91117/spam
Del: non-english -- https://master.php.net/note/delete/91117/non-english
Del: in docs -- https://master.php.net/note/delete/91117/in+docs
Del: other reasons-- https://master.php.net/note/delete/91117
Reject -- https://master.php.net/note/reject/91117
Search -- https://master.php.net/manage/user-notes.php