Generate a PNG containing black

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
garyash
Posts: 5
Joined: 2018-09-13T09:55:44-07:00
Authentication code: 1152

Generate a PNG containing black

Post by garyash »

I'm trying to use perlmagick to automate creating Apple TV icons and I'm having a problem generating an black png file and wondered if anyone could help
The resize fails.

Image Magick version: 7.0.8-11

Code: Select all

#!/usr/bin/env perl
use strict;
use warnings;
use Image::Magick;


my $image = Image::Magick->new(size => "1200x1200");
my $error = $image->Read('canvas:black');
if ("$error") {
	errorMessage($error);
}
$error = $image->Resize(geometry => "800×480!");
if ("$error") {
	errorMessage($error);
}
$image->Write(filename => "AppleTV-Home-Background\@2x.png", compression => "None");
#*****************************************************************************************
# print an error message and exit
#*****************************************************************************************
sub errorMessage {
    print "@_\n";
    exit(2);
}
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Generate a PNG containing black

Post by fmw42 »

I am not a PerlMagic expert. But try xc:black rather than canvas:black
garyash
Posts: 5
Joined: 2018-09-13T09:55:44-07:00
Authentication code: 1152

Re: Generate a PNG containing black

Post by garyash »

that didn't help. The problem seems to be the geometry
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Generate a PNG containing black

Post by fmw42 »

Does it help to replace "800×480!" with "800×480\!"

Do you get any error messages? If so, what are they.

What is the size of the output?

Perhaps the \@ symbol in the output is not a good character. Try changing AppleTV-Home-Background\@2x.png to AppleTV-Home-Background_2x.png or something else without the \@
garyash
Posts: 5
Joined: 2018-09-13T09:55:44-07:00
Authentication code: 1152

Re: Generate a PNG containing black

Post by garyash »

the error I'''m getting now is Exception 410: invalid geometry `800×480!' @ error/geometry.c/ParseRegionGeometry/1629
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Generate a PNG containing black

Post by fmw42 »

Did you try replacing "800×480!" with "800×480\!"

Does it work if you just use "800×480" even though that is not what you want. I am trying to figure out if perhaps Perlmagick does not know about "!"
garyash
Posts: 5
Joined: 2018-09-13T09:55:44-07:00
Authentication code: 1152

Re: Generate a PNG containing black

Post by garyash »

Yes I did use the \! syntax. the error just doesn't't show it. PerlMagick does seem to support that syntax I''ve used it in other scripts

Thanks for your help!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Generate a PNG containing black

Post by snibgo »

What symbol separates the numbers in "800×480"? It should be a lower-case letter "x". You seem to have something else.

EDIT: I've checked the code geometry.c GetGeometry(), and the separator can be upper or lower case (X or x) or ASCII 215, 0xD7, which is Unicode "multiplication sign". So maybe the code shown in the OP is correct, at least for some operations. But not if it is encoded as a multi-byte UTF sequence. I've always used "x", the lower-case letter.
snibgo's IM pages: im.snibgo.com
garyash
Posts: 5
Joined: 2018-09-13T09:55:44-07:00
Authentication code: 1152

Re: Generate a PNG containing black

Post by garyash »

I''ve got it working now... thank you so much
I'm embarrassed to say you seem to right about the x. It would appear that the size specification (I did a cut 'n paste from Apple''s website) likely contained a multiplication character that I mistook for a simple "x"
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Generate a PNG containing black

Post by fmw42 »

Yes, I have noticed that as well on my Mac when I copy from the Preview inspector. Apple does not use a normal x there. So I always replace it when I copy and paste from there with a proper x.

Good catch from snibgo!
Post Reply