note 85700 added to function.imagerotate
| From: | davidathorizon-nighdotorg at osu1 dot php dot net | Date: | Fri, 12 Sep 2008 16:06:52 +0000 |
| Subject: | note 85700 added to function.imagerotate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-144372@lists.php.net to get a copy of this message | ||
I couldn't get the replacements from 'the dot thawk' or 'pilot' to work for
some reason, so here's my own replacement. It uses ImageMagick; binary must be installed, and
you may need to modify the search path. (I didn't use PHP's ImageMagick support for my own
reasons.)
<?php
/**
* imagerotate()
* Debian php5-gd packages do not include imagerotate() due to some convoluted reason.
*
* @param int $angle - same as PHP builtin function
* @param $bgd_color - not implemented, apparently always #FFFFFF
*
* @return same as PHP builtin function
*/
if ( !function_exists( 'imagerotate' ) ) {
function imagerotate( $source_image, $angle, $bgd_color ) {
$angle = 360-$angle; // GD rotates CCW, imagick rotates CW
foreach ( array( '/usr/bin', '/usr/local/bin', '/opt/local/bin',
'/sw/bin' ) as $path ) {
if ( file_exists( $path . '/convert' ) ) {
$imagick = $path . '/convert';
if ( $path == '/opt/local/bin' ) {
$imagick = 'DYLD_LIBRARY_PATH="" ' . $imagick; // some kind of conflict
with MacPorts and MAMP
}
break;
}
}
if ( !isset( $imagick ) ) {
//trigger_error( 'imagerotate(): could not find imagemagick binary, original image
returned', E_USER_WARNING );
return $source_image;
}
$file1 = '/tmp/imagick_' . rand( 10000,99999 ) . '.png';
$file2 = '/tmp/imagick_' . rand( 10000,99999 ) . '.png';
if ( @imagepng( $source_image, $file1 ) ) {
exec( $imagick . ' -rotate ' . $angle . ' ' . $file1 . ' ' .
$file2 );
if ( file_exists( $file2 ) ) {
$new_image = imagecreatefrompng( $file2 );
unlink( $file1 );
unlink( $file2 );
return $new_image;
} else {
//trigger_error( 'imagerotate(): imagemagick conversion failed, original image
returned', E_USER_WARNING );
return $source_image;
}
} else {
//trigger_error( 'imagerotate(): could not write to ' . $file1 . ', original
image returned', E_USER_WARNING );
return $source_image;
}
}
}
?>
----
Server IP: 208.69.120.35
Probable Submitter: 72.43.82.121
----
Manual Page -- http://www.php.net/manual/en/function.imagerotate.php
Edit -- https://master.php.net/note/edit/85700
Del: integrated -- https://master.php.net/note/delete/85700/integrated
Del: useless -- https://master.php.net/note/delete/85700/useless
Del: bad code -- https://master.php.net/note/delete/85700/bad+code
Del: spam -- https://master.php.net/note/delete/85700/spam
Del: non-english -- https://master.php.net/note/delete/85700/non-english
Del: in docs -- https://master.php.net/note/delete/85700/in+docs
Del: other reasons-- https://master.php.net/note/delete/85700
Reject -- https://master.php.net/note/reject/85700
Search -- https://master.php.net/manage/user-notes.php