TIFF Image gets inverted - reproducible

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
mr_walsh

TIFF Image gets inverted - reproducible

Post by mr_walsh »

I'm trying to work with this US post office image file.: https://boxaroo.com/www-pub/out.tif

I'm using the PHP front end to IM.

Whenever I export this file, it ends up inverted.

I'm using IM 6.3.3

One clue is, the original file looks normal in some things (Mac 'Preview') but in Firefox for example the background is yellow. I saw hints of the intercacies of TIFFs on the web but got lost.

BTW, I'm loading in as a blob because in the real system I get the image as a chunk in memory, not a file.

Help!! Thanks!

(sample program)

Code: Select all

<?
   $file_in = "out.tif";
   $file_out  = "out.gif";
   $f = fopen($file_in, "rb");
   $blob = fread($f, filesize($file_in));
   fclose($f);

   $im = NewMagickWand();
   $result = MagickReadImageBlob($im, $blob);
   if ($result)   { echo "works";} else { echo "nope"; exit;}

  // messed with these parms per some posts, had no effect
   MagickSetImageOption($im, "tiff", "photometric", "min-is-black");
   MagickSetImageOption($im, "tiff", "alpha", "unassociated");

   $result = MagickWriteImage($im, $file_out);
   if ($result)   { echo "works";} else { echo "nope"; exit;}
?>
mr_walsh

Re: TIFF Image gets inverted - reproducible

Post by mr_walsh »

Of course it is even easier to reproduce by doing

Code: Select all

convert out.tif out.jpg
mr_walsh

Re: TIFF Image gets inverted - reproducible

Post by mr_walsh »

I was trying to do a workaround by looking at the color of the pixels...what's really weird is that if I look at the pixels inside the loaded TIF image via IM, they seem right...there are way more black pixels than white ones. It's as if the thing gets flipped when I render it to a GIF.

Code: Select all

   $r = MagickGetImageHistogram($im);
   $black = $white = 0;
   foreach ($r as $p)
   {  $tot = PixelGetGreen($p) + PixelGetRed($p) + PixelGetBlue($p);
      if ($tot > 0)
      {  $black = PixelGetColorCount($p);
      }
      else
      {  $white = PixelGetColorCount($p);
      }
   }
   echo "$black , $white"."<BR>";
Post Reply