Voting

: min(four, six)?
(Example: nine)

The Note You're Voting On

david at horizon-nigh dot org
16 years ago
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;

}

}

}
?>

<< Back to user notes page

To Top