Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

[SOLVED] PerlMagick (ImageMagick API): create a new "dummy" PNG file from the ether

by Br'er Rabbit (Novice)
on Sep 26, 2019 at 02:51 UTC ( [id://11106715]=perlquestion: print w/replies, xml ) Need Help??

Br'er Rabbit has asked for the wisdom of the Perl Monks concerning the following question:

How about this one?

Is there a simple way to "use Image::Magic;" (aka PerlMagick, the Perl API to ImageMagick) to create a new "dummy" PNG image out of the ether; that is, no reading in an existing PNG file?

I've been trying for over a week and no matter what I've tried, the "magick" of files I create (which I take to be the file format: like 'PNG') come back as 'MIFF'.

I don't want to pollute the thread with my scattershot stuff that hasn't worked; if you've got a short example, please share.

I will say that my goal is to manipulate the file and Write it after it's created. I don't want to worry about how to "save as a PNG" after doing all the work, and instead, am hoping to create the write type of file before any work is started.

I hit "create" to stumbit and then this works, creating a 10x10 pixel PNG file, which is recognized as a PNG when written and read back in (I'm kinda like a novice monk who sits at the outermost gate talking to hisself):

#!/usr/bin/perl use Image::Magick; my $image=Image::Magick->new(format=>'PNG',size='10x10'); # critical t +o solution was this "format" key my $err=$image->Read("canvas:orange"); warn "$err" if $err; # these are good ideas because PerlMagick sometim +es fails silently $err=$image->Write("CANVAS_ORANGE.png"); warn "$err" if $err; my $other=Image::Magick->new; my $err=$other->Read("CANVAS_ORANGE.png"); warn "$err" if $err; my $format=$other->Get('format'); my $magick=$other->Get('magick'); print "Format:$format Magick:$magick\n";
  • Comment on [SOLVED] PerlMagick (ImageMagick API): create a new "dummy" PNG file from the ether
  • Download Code

Replies are listed 'Best First'.
Re: [SOLVED] PerlMagick (ImageMagick API): create a new "dummy" PNG file from the ether
by roboticus (Chancellor) on Sep 26, 2019 at 13:33 UTC

    Br'er Rabbit:

    Hah, ha! Yes, that's one of the great things about carefully building a small example of a problem: you can often solve it yourself. I've avoided several posts over the years simply by trying to make a simple example program to demonstrate the problem I'm having.

    ...and sometimes it can cause what you've seen: You write the the program, test it, and create your post. Then shortly afterwards, you run it again and it all works. Perhaps you forgot to save the final version of the script (that actually works) or forgot to run it and still have the error output from the previous version on your other console window. I've been there as well. 8^)

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-16 04:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found