Page 1 of 1
Generate a PNG containing black
Posted: 2018-09-13T10:11:06-07:00
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);
}
Re: Generate a PNG containing black
Posted: 2018-09-13T10:58:50-07:00
by fmw42
I am not a PerlMagic expert. But try xc:black rather than canvas:black
Re: Generate a PNG containing black
Posted: 2018-09-13T12:16:29-07:00
by garyash
that didn't help. The problem seems to be the geometry
Re: Generate a PNG containing black
Posted: 2018-09-13T12:24:19-07:00
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 \@
Re: Generate a PNG containing black
Posted: 2018-09-13T13:22:29-07:00
by garyash
the error I'''m getting now is Exception 410: invalid geometry `800×480!' @ error/geometry.c/ParseRegionGeometry/1629
Re: Generate a PNG containing black
Posted: 2018-09-13T13:50:43-07:00
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 "!"
Re: Generate a PNG containing black
Posted: 2018-09-13T14:20:21-07:00
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!
Re: Generate a PNG containing black
Posted: 2018-09-13T14:36:54-07:00
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.
Re: Generate a PNG containing black
Posted: 2018-09-13T18:49:30-07:00
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"
Re: Generate a PNG containing black
Posted: 2018-09-13T19:10:13-07:00
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!