File name containing ':' can't be escaped if frame used

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
ache
Posts: 4
Joined: 2012-04-19T06:37:40-07:00
Authentication code: 13

File name containing ':' can't be escaped if frame used

Post by ache » 2012-04-19T06:42:14-07:00

Hi.
PerlMagick from IM 6.7.5-10 can't process first frame in file names with ':' inside because it always mistreat the first part before ':' as image format. I try to escape ':' with backslashes, but it does not help (I try with 1-4 backsklashes). I mean calls like that:
$imagename = "foo:bar.ext";
$image->Read("${imagename}\[0\]");
Error: Exception 420: no decode delegate for this image format `bar.ext' @ error/constitute.c/ReadImage/532
Single backslash works, only if no ...[0] part present, i.e. that works:
$imagename = "foo\:bar.ext";
$image->Read("${imagename}");
but that don't:
$imagename = "foo\:bar.ext";
$image->Read("${imagename}\[0\]");
Following workaround
$imagename = "GIF:foo\:bar.ext";
requires image format be known at the moment of reading, which is not always so.
Please fix this bug. I remember that some old IM versions does not have it.

User avatar
anthony
Posts: 8877
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: File name containing ':' can't be escaped if frame used

Post by anthony » 2012-04-23T22:46:44-07:00

Note that doing

Code: Select all

  $imagename = "foo\:bar.ext";
done NOTHING in perl. You escaped the ':' in the double quotes which for perl just removes the backslash.

To pass teh bashslash to Imagemagick you need to escape the backshash itself!!!!
that is you need to use....

Code: Select all

  $imagename = "foo\\:bar.ext";
the alturnative is to use single quotes! But then you can insert variables into the string!

Code: Select all

    $imagename = 'foo\:bar.ext';

Know your perl!

I am thinking that a 'literal file name read' type setting should be added as this can be useful for both API's (like perl) and for command line. I have a note about something like that for the current Imv7 development but it is close to the bottom of the very long to-do list.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

ache
Posts: 4
Joined: 2012-04-19T06:37:40-07:00
Authentication code: 13

Re: File name containing ':' can't be escaped if frame used

Post by ache » 2012-04-23T23:08:31-07:00

I already mention that I try with 1-4 backslashes with the same result (and both types of quotes). Here is full script with the string you suggest as working:

Code: Select all

#!/usr/bin/perl -w
use Image::Magick;
my $imagename = 'foo\:bar.ext[0]';
my $image = Image::Magick->new;
my $status = $image->Read($imagename);
print "$status\n" if ($status);

Code: Select all

Exception 420: no decode delegate for this image format `bar.ext' @ error/constitute.c/ReadImage/532
BTW, another string you suggest "foo\\:bar.ext\[0\]" does not work too.
Adding literal flag will be good, but currently it is obvious parser regression: ":" can't be escaped when reading [frame]

User avatar
magick
Site Admin
Posts: 10908
Joined: 2003-05-31T11:32:55-07:00

Re: File name containing ':' can't be escaped if frame used

Post by magick » 2012-04-24T04:12:53-07:00

The problem you reported should be fixed in ImageMagick 6.7.6-7. If you have further problems, let us know.

ache
Posts: 4
Joined: 2012-04-19T06:37:40-07:00
Authentication code: 13

Re: File name containing ':' can't be escaped if frame used

Post by ache » 2012-05-16T15:50:03-07:00

magick wrote:The problem you reported should be fixed in ImageMagick 6.7.6-7. If you have further problems, let us know.
I just test this example

Code: Select all

#!/usr/bin/perl -w
use Image::Magick;
my $imagename = 'foo\:bar.ext[0]';
my $image = Image::Magick->new;
my $status = $image->Read($imagename);
print "$status\n" if ($status);
with IM 6.7.6-9 (I try 0..2 backlashes).
Still get:

Code: Select all

Exception 420: no decode delegate for this image format `bar.ext' @ error/constitute.c/ReadImage/544
So, apparently nothing is changed excepting line number in the diagnostic.

User avatar
magick
Site Admin
Posts: 10908
Joined: 2003-05-31T11:32:55-07:00

Re: File name containing ':' can't be escaped if frame used

Post by magick » 2012-05-16T16:58:15-07:00

This seems to work:
  • -> convert logo: rose: gif:foo:bar.ext
    -> display 'gif:foo:bar.ext[1]'
or
  • convert logo: rose: foo:bar.gif
    display 'implicit:foo:bar.gif[1]'
    display ':foo:bar.gif[1]'

User avatar
anthony
Posts: 8877
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: File name containing ':' can't be escaped if frame used

Post by anthony » 2012-05-21T17:30:41-07:00

I have not seen the syntax "implicit::..." or even ":..." before.

Does implicit: also make the read modifier implicit?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

ache
Posts: 4
Joined: 2012-04-19T06:37:40-07:00
Authentication code: 13

Re: File name containing ':' can't be escaped if frame used

Post by ache » 2012-05-21T18:03:06-07:00

First one works because you directly specify pre-known format. But format of the file can be not known. Extension sometimes hides real format, f.e. some image hostings preserve .GIF on uploaded file but put JPEG format inside.

Second one in 6.7.6-9

Code: Select all

my $imagename = 'implicit::foo:bar.ext[0]';
gives error:

Code: Select all

Exception 435: unable to open image `:foo:bar.ext': No such file or directory @ error/blob.c/OpenBlob/2617
Third version

Code: Select all

my $imagename = ':foo:bar.ext[0]';
works, thanks. However this kind of escaping looks a little strange and not intuitive.

Update: implicit: (with one colon instead of two) works, thanx.

User avatar
anthony
Posts: 8877
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: File name containing ':' can't be escaped if frame used

Post by anthony » 2012-05-21T19:07:11-07:00

Thanks for the clarification.

However I know from looking at code, that an 'implicit:' prefix will not prevent IM expanding globs ('*' and '?'), at least in the Shell API (does not apply to other API's)

so if you have a filename called "implicit:abc.jpg"
and you request "implicit:*.jpg" (with quotes to prevent shell glob expansion)
IM may still expand that

For example

Code: Select all

convert rose: t.jpg
mv t.jpg implicit:abc.jpg
convert 'implicit:*.jpg' show:
will still show the 'rose:' image from implicit:abc.jpg

This would currently happen in BOTH IMv6 (global glob expansion) and IMv7 (which restricts glob expansion to image reads only).


Summary....

At this time filenames may have the following expansions, (from my Shell API project list)

Code: Select all

      filelist       @filelist.txt
      glob           use of '~', '*', and '?'
      coder          CODER: prefix
      read_mods      [...] postfix   (read only at this time)
      escape         %[filename:...]  (write only at this time)
      enumeration    %d formatting (using -scenes for read (undocumented)
                                    or a[#,#-#] read modifier, and -scene for write)
I hope to add a setting (sometime during beta development) to selectively enable/disable these expansions.
This would work better than the use of 'implicit:' which is itself an expansion.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

Post Reply