Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Image Magick branding module crash

by GrandFather (Saint)
on Sep 10, 2005 at 04:49 UTC ( #490836=perlquestion: print w/replies, xml ) Need Help??

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

I'm trying the sample code (see below) from the Image::Magick::Brand module using a .jpg and .gif file to produce a .jpg and the program crashes. Is there a known problem or some version conflict, or am I likely to have installed something incorrectly?

I'm using Active State Perl v5.8.7 built for MSWin32-x86-multi-thread, ImageMagick-6.2.4-Q16 and Image::Magick::Brand 0.01 (installed using ppm).

use Image::Magick::Brand; my $b = new Image::Magick::Brand; # Required parameters $b->brand( source => 'x.gif', target => 'xjpg', output => 'xb.jpg' );

Perl is Huffman encoded by design.

Replies are listed 'Best First'.
Re: Image Magick branding module crash
by davidrw (Prior) on Sep 10, 2005 at 13:05 UTC
    a few comments:
    • try $b->{debug} = 1; between 'new' and 'brand' lines ... anything useful?
    • note you should probably pass a format=>'jpg' param as well (happens to default to jpg)
    • is the target really 'xjpg' or should that be 'x.jpg'? maybe w/o an extension Image::Magick can't figure it out?
    • Do you have the proper libs installed? Can you use straight IM code (two new/Read's and a Composite) and does that work?
      use Image::Magick; my $image = Image::Magick->new(); $image->ReadImage( 'x.jpg' ); my $pic = Image::Magick->new(); $pic->ReadImage( 'x.gif' ); $pic->Scale( width=>$w, height=>$h ); $image->Composite( image=>$pic, x=>$x, y=>$y, compose=>'Over' ); $image->Write( 'xb.jpg' );
    • note that Image::Magick::Brand is just a very simple (and limited) wrapper around the Composite() method so if the problem is there it's easy enough to just not use it .. (see above item for code)

    Also, using Imager may be an alternative:
    use Image; my $image = Imager->new; $image->read(file=>'x.jpg', type=>'jpeg') or die "Cannot read: + ", $image->errstr; my $pic = Imager->new; $pic->read(file=>'x.gif', type=>'gif') or die "Cannot read: ", + $pic->errstr; $image->paste( left=>$x, top=>$y, img=> $pic->scale( xpixels=>$w, ypixels=>$h, type=>'min' ), ); $image->write(file=>"xb.jpg");

      Excellent answer davidrw!

      a few replys:

      1. Initial code included the debug line, but it didn't tell me anything useful so I removed it to simplify the problem
      2. Noted :)
      3. I committed the sin of "editing the code for publication" and deleted the fullstop. It was a .jpg.
      4. The code you supplied works fine and is an excellent starting point for the problem I need to solve.
      5. Noted and much appreciated

      This is my first venture into using Image Magick. It was in the context of showing Great GrandFather how wonderfull Perl is and how he could save so much time with a small Perl tool used to brand pictures to be put on a web site. The result wasn't quite as impressive as I'd hoped :). Honour will be regained however - thank you.


      Perl is Huffman encoded by design.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2021-10-19 12:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (76 votes). Check out past polls.

    Notices?