IM can't handle %% in paths

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
akes
Posts: 4
Joined: 2018-03-20T23:48:00-07:00
Authentication code: 1152

IM can't handle %% in paths

Post by akes »

I have a problem with folders that contains %% and that I use [0] in the conversion. I see in the path from the error message that one % is "lost". Can some help me please?

### Test with folder that ends with %% and using[0], fails.
# convert ./karsten\ 93%%/Kalle.png[0] -profile /usr/local/axpa/webimage/iccs/sRGB.icc -geometry "1000x1000>" -depth 8 /tmp/tmp_sam.tif
convert: unable to open image './karsten 93%/Kalle.png': No such file or directory @ error/blob.c/OpenBlob/3375.
convert: no images defined `/tmp/tmp_sam.tif' @ error/convert.c/ConvertImageCommand/3275.
# identify /tmp/tmp_sam.tif
identify: unable to open image '/tmp/tmp_sam.tif': No such file or directory @ error/blob.c/OpenBlob/3375.

### Test with folder that ends with %% and without [0], works.
# convert ./karsten\ 93%%/Kalle.png -profile /usr/local/axpa/webimage/iccs/sRGB.icc -geometry "1000x1000>" -depth 8 /tmp/tmp_sam.tif
convert: delegate library support not built-in './karsten 93%%/Kalle.png' (LCMS) @ warning/profile.c/ProfileImage/836.
# identify /tmp/tmp_sam.tif
/tmp/tmp_sam.tif TIFF 544x687 544x687+0+0 8-bit sRGB 46952B 0.000u 0:00.009

# identify -version
Version: ImageMagick 7.0.7-26 Q16 x86_64 2018-03-15 http://www.imagemagick.org
Copyright: © 1999-2018 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI OpenMP
Delegates (built-in): cairo fontconfig freetype jng jpeg lzma png rsvg tiff x xml zlib


I'm running this on CentOS 7

Thanks
Åke
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: IM can't handle %% in paths

Post by Bonzo »

Why on earth would you want %% in a folder name?

Try putting you full image path in ""

Version 7 uses magick now over convert
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: IM can't handle %% in paths

Post by snibgo »

akes wrote:I see in the path from the error message that one % is "lost". Can some help me please?
So, if "%%" is converted to "%", and you need "%%", then you should type "%%%%".
snibgo's IM pages: im.snibgo.com
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: IM can't handle %% in paths

Post by Bonzo »

So, if "%%" is converted to "%", and you need "%%", then you should type "%%%%".
If you look at the OP's input file path ./karsten\ 93%%/Kalle.png[0] it contains %% along with a white space and both \ and / :shock:
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: IM can't handle %% in paths

Post by snibgo »

Yes, the "/" is a directory delimiter in bash, and "\ " is a literal space within the directory name. I expect this command will work:

Code: Select all

convert ./karsten\ 93%%%%/Kalle.png[0] -profile /usr/local/axpa/webimage/iccs/sRGB.icc -geometry "1000x1000>" -depth 8 /tmp/tmp_sam.tif
Personally, I don't allow special characters like % or spaces in filenames (which include directories). They are more trouble than they are worth.
snibgo's IM pages: im.snibgo.com
akes
Posts: 4
Joined: 2018-03-20T23:48:00-07:00
Authentication code: 1152

Re: IM can't handle %% in paths

Post by akes »

To stop 100+ users from using unwanted characters in file and folder names is a Sisyphean task. I think its something internal in IM since it only happens when I have %% in the path and [0] specified. Changing path in command from %% to %%%% works, but would require a change in the code that generates the IM commands.
246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: IM can't handle %% in paths

Post by 246246 »

Even without [0], this command failed also:

Code: Select all

$ mkdir tmp%%
$ magick logo: 'tmp%%/logo.tif'
magick.exe: unable to open image 'tmp%/logo.tif': No such file or directory @ error/blob.c/OpenBlob/3109.

With -debug TRACE it disappears around here:

Code: Select all

...
2018-03-22T18:51:45+09:00 0:00.348 0.125u 7.0.6 Trace magick.exe[11600]: ../ImageMagick-7.0.6-7/MagickCore/option.c/DestroyImageOptions/2004/Trace
  tmp%%/logo.tif
2018-03-22T18:51:45+09:00 0:00.348 0.125u 7.0.6 Trace magick.exe[11600]: ../ImageMagick-7.0.6-7/MagickCore/image.c/DestroyImageInfo/1253/Trace
2018-03-22T18:51:45+09:00 0:00.348 0.125u 7.0.6 Trace magick.exe[11600]: ../ImageMagick-7.0.6-7/MagickCore/option.c/DestroyImageOptions/2004/Trace
2018-03-22T18:51:45+09:00 0:00.348 0.125u 7.0.6 Trace magick.exe[11600]: ../ImageMagick-7.0.6-7/MagickCore/property.c/InterpretImageProperties/3350/Trace
  tmp%/logo.tif
...
Last edited by 246246 on 2018-03-22T03:55:45-07:00, edited 1 time in total.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: IM can't handle %% in paths

Post by Bonzo »

So what you are saying is that you want Imagemagick to be rewritten just to help you?

I suggest in your code you copy the file to a location without any % or other problem characters and rename it to make sure there are none in the name.
Run the Imagemagick code on the image and save it back to the temporary location.
Copy/move it back to the new/original location renaming it with the problem characters

Or put your foot down and tell the users not to use anything other than alphanumeric characters and underscores.
akes
Posts: 4
Joined: 2018-03-20T23:48:00-07:00
Authentication code: 1152

Re: IM can't handle %% in paths

Post by akes »

Bonzo wrote: 2018-03-22T03:35:44-07:00 So what you are saying is that you want Imagemagick to be rewritten just to help you?
No, but I think it's a bug. Since I do not have the capabilities to check if it's so, I hope someone with the right knowledge will.
And since some of the images are 300MB+ I do not want to copy them before running the IM command.
246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: IM can't handle %% in paths

Post by 246246 »

akes wrote: 2018-03-22T06:29:02-07:00 And since some of the images are 300MB+ I do not want to copy them before running the IM command.
As you are in linux, you can use mv instead of cp if the partition is same.
Probably better way is to use symbolic link.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: IM can't handle %% in paths

Post by Bonzo »

There was a similar post a while ago and nothing was changed and it was not treated as a bug: viewtopic.php?f=1&t=33537

As I said I think you should just stop people from using any character they want. I can not believe they can not name a folder or a file without resorting to symbols. What is to stop somebody creating a filename that when it is loaded into Imagemagick it compromises or crashes your server?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: IM can't handle %% in paths

Post by fmw42 »

Sanitize your file and folder names in your OS before using in Imagemagick.

Did you try Bonzo's suggestion of enclosing the full path including the file and [0] inside double quotes?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: IM can't handle %% in paths

Post by snibgo »

The difficulty is that IM treats some characters in output filenames as special. For example "output_%[filename:mysize].tif" will substitute %[...] with something else.

IM doesn't (sadly) have an option for "don't treat any characters as special in output filenames". Instead, it uses an escape mechanism -- if you want "%" you need to put "%%", etc.

(In the same say, the C-language "printf(msg)" will always treat "%" in msg as special.)

It certainly isn't a bug: "%" is a special character to IM. I'd like an option for "don't treat any characters as special in output filenames". But I doubt it will be implemented.

If this is a common problem, symbolic links may be the solution.
snibgo's IM pages: im.snibgo.com
246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: IM can't handle %% in paths

Post by 246246 »

snibgo wrote: 2018-03-22T16:15:20-07:00 The difficulty is that IM treats some characters in output filenames as special. For example "output_%[filename:mysize].tif" will substitute %[...] with something else.
Thank you for reminding me. I had thought the result in my simple testcase is an obvious bug. :)
Last edited by 246246 on 2018-07-11T05:53:39-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: IM can't handle %% in paths

Post by snibgo »

Another example:

Code: Select all

convert rose: r%d.png
IM interprets "%d", so the output is named "r0.png".

Code: Select all

convert rose: r%%d.png
The "%" is escaped by a "%", so it is de-escaped to "%", and the output is named "r%d.png".

Code: Select all

convert rose: r%.png
"%" isn't followed by anything magical, so the output is named "r%.png".

Code: Select all

convert rose: r%%.png
The "%" is escaped by a "%", so this output is also named "r%.png".

Code: Select all

convert rose: r%%%.png
The first two are de-escaped to a single "%", and the final "%" isn't followed by anything magical, so the output is named "r%%.png".

And so on.
snibgo's IM pages: im.snibgo.com
Post Reply