For me, unchecking downsampling option is also a workaround. It seems that libpdf-api2-perl doesn't like
convert -depth 8 -resize 516x730 input.png input.tif
Then the script below with PDF::API2 produces the inverted colours.
input.png[1] PNG 2481x3508 2481x3508+0+0 8-bit PseudoClass 256c 226KB 0.000u 0:00.000 input.tif[2] TIFF 516x730 516x730+0+0 8-bit DirectClass 228KB 0.000u 0:00.000
Without the -resize option, the colours are fine.
input.png[1] PNG 2481x3508 2481x3508+0+0 8-bit PseudoClass 256c 226KB 0.000u 0:00.009 input.tif[2] TIFF 2481x3508 2481x3508+0+0 8-bit PseudoClass 256c 239KB 0.000u 0:00.000
So it looks as though libpdf-api2-perl doesn't like DirectClass TIFFs:
convert -depth 8 -resize 516x730 -type palette input.png input.tif
input.tif TIFF 516x730 516x730+0+0 8-bit PseudoClass 256c 93.5KB 0.000u 0:00.000
And yes - the colours are then correct.
#!/usr/bin/perl -w use strict; use PDF::API2; use Image::Magick; my $pdf = PDF::API2-> new(-file => 'test.pdf'); my $image = Image::Magick->new; $image->Read('input.tif'); my $resolution = $image->Get('x-resolution'); my $w = $image->Get('width') / $resolution; my $h = $image->Get('height') / $resolution; my $page = $pdf->page; $page->mediabox( $w * 72, $h * 72 ); my $gfx = $page->gfx; my $img = $pdf->image_tiff($tiff); $gfx->image( $img, 0, 0, $w * 72, $h * 72 ); $pdf->save; $pdf->end;
For me, unchecking downsampling option is also a workaround. It seems that libpdf-api2-perl doesn't like
convert -depth 8 -resize 516x730 input.png input.tif
Then the script below with PDF::API2 produces the inverted colours.
input.png[1] PNG 2481x3508 2481x3508+0+0 8-bit PseudoClass 256c 226KB 0.000u 0:00.000
input.tif[2] TIFF 516x730 516x730+0+0 8-bit DirectClass 228KB 0.000u 0:00.000
Without the -resize option, the colours are fine.
input.png[1] PNG 2481x3508 2481x3508+0+0 8-bit PseudoClass 256c 226KB 0.000u 0:00.009
input.tif[2] TIFF 2481x3508 2481x3508+0+0 8-bit PseudoClass 256c 239KB 0.000u 0:00.000
So it looks as though libpdf-api2-perl doesn't like DirectClass TIFFs:
convert -depth 8 -resize 516x730 -type palette input.png input.tif
input.tif TIFF 516x730 516x730+0+0 8-bit PseudoClass 256c 93.5KB 0.000u 0:00.000
And yes - the colours are then correct.
#!/usr/bin/perl -w >Read(' input.tif' ); >Get('x- resolution' ); >Get('width' ) / $resolution; >Get('height' ) / $resolution; tiff($tiff) ;
use strict;
use PDF::API2;
use Image::Magick;
my $pdf = PDF::API2-> new(-file => 'test.pdf');
my $image = Image::Magick->new;
$image-
my $resolution = $image-
my $w = $image-
my $h = $image-
my $page = $pdf->page;
$page->mediabox( $w * 72, $h * 72 );
my $gfx = $page->gfx;
my $img = $pdf->image_
$gfx->image( $img, 0, 0, $w * 72, $h * 72 );
$pdf->save;
$pdf->end;