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

Hi,

I am using GD and GD-Tiles to edit a png image. Everything works fine but i would like to eliminate one step and directly use the return value from GD-Tiles for the resize call. Image::Resize return a GD value. Here my code:

use GD; use GD::Tiler qw(tile); my $GDimage = newFromPng GD::Image("foo.png"); my ($width,$height) = $GDimage->getBounds() ; #... i still do some stuff with GD here my $png_data = $GDimage->png; my $explimg = tile( Images => [ $png_data, "bar.png"], Background => 'transparent', Width => $width, Height => $height, Coordinates => [ 0, 0, $mx, $my, ], ); #START I would like to save this and directly use $explimg to resi +ze. open (DISPLAY, ">temp.png"); binmode DISPLAY; print DISPLAY $explimg; close (DISPLAY); #EOF START my $old = Image::Resize->new("temp.png"); #my $old = Image::Resize->new($explimg); does not WORK!!! my $new = $old->resize(800, 600); open (DISPLAY, ">final.png"); binmode DISPLAY; print DISPLAY $new->png; close (DISPLAY);
Any ideas

Thanks

Henrik

Replies are listed 'Best First'.
Re: Perl GD
by almut (Canon) on Jan 17, 2010 at 18:38 UTC
    #my $old = Image::Resize->new($explimg); does not WORK!!!

    According to the docs, it should work.  I.e., GD::Tiler's tile() claims it returns a GD::Image object, and Image::Resize's constructor says "can accept either GD::Image object, or file system path".  So that brings up the question what exactly does "does not WORK" mean? Any errors? What object type is indicated by ref($explimg), etc.?

      Thanks for your reply.

      print ref($explimg); does not return anything.

      If i use the code:
      my $old = Image::Resize->new($explimg); my $new = $old->resize(800, 600);
      It prints the png binary data an my command shell crash. But i actually solved the problem with this code:
      use GD; my $GDimage = newFromPng GD::Image("imago_temp.png"); my ($width,$height) = $GDimage->getBounds() ; $newimage = GD::Image->new(800,600); $newimage->copyResampled($GDimage,0,0,0,0,800,600 ,$width,$height) +; open (DISPLAY, ">snapshot.jpg"); binmode DISPLAY; print DISPLAY $newimage->jpeg(100); close (DISPLAY);