Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

PerlMagick Scene attribute

by BrentD (Sexton)
on Sep 26, 2017 at 22:05 UTC ( [id://1200157]=perlquestion: print w/replies, xml ) Need Help??

BrentD has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to use PerlMagick to convert PDFs into multiple TIFF images. For the most part everything is working, except for the file numbering. Normally I'd just call

'convert -density 240x240 -compress Group4 -scene 15 test.pdf testp%04d.tif'

to get files tiffp0015.tif though testp0018.tif (for a 4-page PDF). I tried to translate this into PerlMagick with the following code:
#!/usr/bin/perl use strict; use warnings; use Image::Magick; my $image = Image::Magick->new; my $filename = "test.pdf"; $image->Read($filename); $image->Set(scene=>15); $image->Write(filename=>"testp%04d.tif", compression=>'Group4', density=>"240x240");

but it is still outputting testp0000.tif - testp0003.tiff

How do I get it to start with the correct scene number?

Replies are listed 'Best First'.
Re: PerlMagick Scene attribute
by syphilis (Archbishop) on Sep 26, 2017 at 23:01 UTC
    Have you tried:
    $image->Write(filename=>"testp%04d.tif", compression=>'Group4', density=>"240x240", scene=>15);
    Untested.

    Cheers,
    Rob
      Yes. Also tried the following variants with the same result: Variant 1:
      $image->Read($filename); $image->[0]->Set(scene=>15); $image->Write(filename=>"testp%04d.tif", compression=>'Group4', density=>"240x240");
      Variant 2:
      $image->Read($filename); $image->Write(filename=>"testp%04d.tif", compression=>'Group4', density=>"240x240", scene=>15);
      And just in case the order of attributes made a difference in the "Write" command:
      Variant 3:
      $image->Read($filename); $image->Write(scene=>15, filename=>"testp%04d.tif", compression=>'Group4', density=>"240x240");
Re: PerlMagick Scene attribute
by BrentD (Sexton) on Sep 27, 2017 at 15:50 UTC
    So, trying to narrow down the problem I wanted to verify that "scene" is in fact getting set:
    #!/usr/bin/perl use strict; use warnings; use Image::Magick; unlink (glob("*.tif")); my $image = Image::Magick->new; my $filename = "test.pdf"; $image->Read($filename); my $p = $image->Get('scene'); print "\n\nScene1: $p\n"; $image->Set(scene=>15); $p = $image->Get('scene'); print "Scene2: $p\n\n"; $image->Write(filename=>"testp%04d.tif", compression=>'Group4', density=>"240x240");
    My output is:
    Scene1: 0 Scene2: 15
    So it appears as if "scene" is being properly set, but that it's being ignored by the Write method.
       $image[14]->Write...?

        Inventing a new syntax won't fix the problem. There is no @image array around.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: PerlMagick Scene attribute
by Anonymous Monk on Sep 26, 2017 at 23:16 UTC
    Have you tried passing "scene => 15" to ->Set? Also, are you sure compression and compress are related?
      Yes, according to the API spec at https://www.imagemagick.org/script/perl-magick.php the compression attribute is the same as -compress.

      The 4 TIFF files that it outputs have the correct compression, just the wrong filenames.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1200157]
Approved by johngg
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (1)
As of 2024-04-24 14:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found