Page 1 of 2
IM can't handle %% in paths
Posted: 2018-03-21T00:06:32-07:00
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
Re: IM can't handle %% in paths
Posted: 2018-03-21T00:55:44-07:00
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
Re: IM can't handle %% in paths
Posted: 2018-03-21T02:56:12-07:00
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 "%%%%".
Re: IM can't handle %% in paths
Posted: 2018-03-21T03:37:22-07:00
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 /
Re: IM can't handle %% in paths
Posted: 2018-03-21T03:49:06-07:00
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.
Re: IM can't handle %% in paths
Posted: 2018-03-22T01:30:41-07:00
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.
Re: IM can't handle %% in paths
Posted: 2018-03-22T02:40:11-07:00
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
...
Re: IM can't handle %% in paths
Posted: 2018-03-22T03:35:44-07:00
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.
Re: IM can't handle %% in paths
Posted: 2018-03-22T06:29:02-07:00
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.
Re: IM can't handle %% in paths
Posted: 2018-03-22T07:04:36-07:00
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.
Re: IM can't handle %% in paths
Posted: 2018-03-22T08:30:39-07:00
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?
Re: IM can't handle %% in paths
Posted: 2018-03-22T09:04:27-07:00
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?
Re: IM can't handle %% in paths
Posted: 2018-03-22T16:15:20-07:00
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.
Re: IM can't handle %% in paths
Posted: 2018-03-22T17:30:20-07:00
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.
Re: IM can't handle %% in paths
Posted: 2018-03-22T22:12:37-07:00
by snibgo
Another example:
IM interprets "%d", so the output is named "r0.png".
The "%" is escaped by a "%", so it is de-escaped to "%", and the output is named "r%d.png".
"%" isn't followed by anything magical, so the output is named "r%.png".
The "%" is escaped by a "%", so this output is also named "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.