Code: Select all
<?php
$max_x = $_GET['x'];
$max_y = $_GET['y'];
$filename = $_GET['src'];
if( $image = NewMagickWand() ) {
MagickReadImage( $image, $filename );
MagickSetImageColorspace( $image, MW_RGBColorspace );
MagickStripImage( $image );
MagickProfileImage( $image, 'SWAP', 'USWebCoatedSWOP.icc');
MagickProfileImage( $image, 'RGB', 'AdobeRGB1998.icc');
$cur_x = MagickGetImageWidth( $image );
$cur_y = MagickGetImageHeight( $image );
if ($cur_x >= $cur_y) {
$cur_rat = ($max_x * 1.000) / ($cur_x * 1.000);
$x = $max_x;
$y = ($cur_y * 1.000) * $cur_rat;
}
else {
$cur_rat = ($max_y * 1.000) / ($cur_y * 1.000);
$y = $max_y;
$x = $cur_x * $cur_rat;
}
//echo MagickGetImageProfile( $image, "rgb" );
header( 'Content-Type: image/jpg' );
if(MagickGetImageWidth( $image ) > $x && MagickGetImageHeight( $image ) > $y)
{
MagickResizeImage( $image, $x, $y, MW_SincFilter, 1 );
}
MagickSetImageFormat( $image, 'jpg' );
//MagickSetImageType( $image, MW_OptimizeType);
MagickEchoImageBlob( $image );
} else {
echo "Error in MagickReadImage()";
echo MagickGetExceptionString($image);
}
?>
converted with command line: convert -colorspace RGB thumb.pdf thumb.jpg
converted with magickWand: