note 54155 added to function.imagecreatetruecolor
| From: | send at mail dot 2aj dot net | Date: | Sat, 25 Jun 2005 02:40:46 +0000 |
| Subject: | note 54155 added to function.imagecreatetruecolor | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-90929@lists.php.net to get a copy of this message | ||
If you want a simple way to mirror images, use the function I've included below.
<?php
function image_mirror ($input_image_resource)
{
$width = imagesx ( $input_image_resource );
$height = imagesy ( $input_image_resource );
$output_image_resource = imagecreatetruecolor ( $width, $height );
$y = 1;
while ( $y < $height )
{
for ( $i = 1; $i <= $width; $i++ )
imagesetpixel ( $output_image_resource, $i, $y, imagecolorat ( $input_image_resource, ( $i ), (
$height - $y ) ) );
$y = $y + 1;
}
return $output_image_resource;
}
?>
Example Usage:
<?php
// A good use of this is when a user uploads a TGA file,
// on the completion screen show the image and have a link
// that asks if the image appears mirrored, and if so
// that link will execute these commands below.
// I suggest checking $HTTP_REFERER for security.
// $_GET['file'] in this case would be something along the lines
// of johndoe-img0001 (Basename is necessary to prevent
// abuse of this script!)
if ( isset( $_GET['file'] ) )
{
$filename = "./" . basename ( $_GET['file'] ) . ".jpg";
// Making the image resource that needs to be mirrored
// Taking it from a previously exported to JPEG file.
$output_resource_image = image_mirror ( imagecreatefromjpeg ( $filename ) );
if ( imagejpeg ( $output_resource_image, $filename, 75 ) )
echo "Image resaved successfully";
else
echo "Image couldn't be written over (Check permissions)!";
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.imagecreatetruecolor.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54155
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54155&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54155&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54155&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54155&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54155&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54155&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54155&report=yes
Search -- http://master.php.net/manage/user-notes.php