Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Appending an image to a png file

by Nalina (Monk)
on Aug 03, 2004 at 10:26 UTC ( [id://379571]=perlquestion: print w/replies, xml ) Need Help??

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

I installed Image::Magick successfully. No more errors. My script to copy an image is
#!/usr/local/bin/perl use Image::Magick; my($image, $x); $image = Image::Magick->new; $x = $image->Read('D:/d/FirewallRespTimebyDay.xls.0.PNG'); warn "$x" if "$x"; $x = $image->Write('C:/Graph.xls.01.08.2004.PNG'); warn "$x" if "$x";
when I run this script, it replaces the image in 'C:/Graph.xls.01.08.2004.PNG' with the image in 'D:/d/FirewallRespTimebyDay.xls.0.PNG'(i.e. it is writting in to the 'C:/Graph.xls.01.08.2004.PNG'). But I want to append an image to the file. I tried
$x = $image->Append('C:/Graph.xls.01.08.2004.PNG');
But got a message saying
Image::Magick=ARRAY(0x1a453b0) at D:\image.pl line 8.
How do I append an image to a png file which already has an image?

Thanks & Regards

Nalina

Replies are listed 'Best First'.
Re: Appending an image to a png file
by davidj (Priest) on Aug 03, 2004 at 11:30 UTC
    Check out this for a good document on using Image::Magick. I pulled the following off the website:

    "The Append() method
    append a set of images. For example,

    $p = $image->Append(stack=>{true,false});
    appends all the images associated with object $image. By default, images are stacked left-to-right. Set stack to True to stack them top-to-bottom."

    Clearly the way you are trying to use the Append method is incorrect.

    Sorry, but as I have never used the program or the package, this is as much help as I can offer.

    davidj

      I tried using append function, the script is as follows.
      #!/usr/local/bin/perl use Image::Magick; my($image, $p, $q); $image = new Image::Magick; $image->Read('d:\\d\\Graph.xls..PNG','d:\\d\\Sample.jpg'); $p = $image->Append(stack=>{true,false}); $p = $image->Write('d:/pimage.jpg');
      this creates 2 files 'pimage.jpg.0' & 'pimage.jpg.1', and the read file images are placed in these two files. But I have mentioned the o/p file name as 'pimage.jpg'. I want both the images to be in the same file(pimage.jpg). How can I get it?

      Thanks & Regards

      Nalina
Re: Appending an image to a png file
by Joost (Canon) on Aug 03, 2004 at 11:34 UTC
      I mean I want to read two png files and write the read images to an another png file OR read a png file and append the image in that file to an another png file.

      I tried
      use Image::Magick; $image = Image::Magick->new; open(IMAGE, 'd:\d\Sample.jpg'); print "test1\n"; $image->Read(file=>\*IMAGE); print "test2\n"; close(IMAGE); $filename = "test.png"; open(IMAGE, ">>$filename"); $image->Write(file=>\*IMAGE, filename=>$filename); close(IMAGE);
      but got an Application error saying,
      The instruction at "0x77f88216" referenced memory at "0x00000010". The + memory could not be "written". Click on OK to terminate the program.
      How to resolve this error?

      Thanks & Regards

      Nalina
Re: Appending an image to a png file
by beable (Friar) on Aug 03, 2004 at 11:34 UTC
    Can you do that to a PNG file? I thought that a PNG file has within it data to tell how large the image is; so if you append another image to the end of the file, you'll end up with the same image except with junk on the end which is the second image. What does it mean to "append an image to a png file which already has an image"? Why do you want to do this?
      If a png file can not be appended, atleast it can be written. How do I write images from 2 different png files to a single png file?

      I tried
      #!/usr/local/bin/perl use Image::Magick; my($image, $p, $q); $image = new Image::Magick; $image->Read('d:\\d\\Graph.xls..PNG','d:\\d\\Sample.jpg'); $image->Write('d:\\pimage.jpg');
      but this writes the images to two files 'pimage.jpg.0' & 'pimage.jpg.1'(each having one image). I want both the images to be in a single png file. How do I get it?

      Thanks & Regards

      Nalina
        Let's suppose you have two png images, one with a red background with a green circle on it; and the other one with a blue background with a yellow triangle on it. What output would you like to get?
Re: Appending an image to a png file
by Anonymous Monk on Aug 03, 2004 at 15:23 UTC
    I suppose you're not trying to create an animation? Because PNG can't be used for that. But you already knew that, of course.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-26 03:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found