CMYK pdf -> RGB jpg color loss

MagickWand for PHP is an object-oriented PHP interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning MagickWand for PHP.
Post Reply
nate12o6

CMYK pdf -> RGB jpg color loss

Post by nate12o6 »

i have magickWand setup for php and when i convert a vector cmyk pdf to rgb jpg i lose a few colors making the final image look horrable. When i convert these images on the command line it looks just fine. I only get the problem when using magickwand. I have looked around and saw some stuff about having to use profiles(i am not an image export so im not 100% sure what a profile is although i tried) so this is my php source:


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);
  }
?>
the profiles that i added dont look to make any difrence. I got them off my windows machine and figured i would just give it a try. If anyone could lead me in the right direction i would very much apreciate it. Thanks!

converted with command line: convert -colorspace RGB thumb.pdf thumb.jpg
Image

converted with magickWand:
Image
Post Reply