Issue
I was trying to batch reduce the quality of some of the images on my system stored at the location
~/sandboxArea/MainCam
and I ran the following command
for i in $(ls ~/sandboxArea/MainCam); do convert $i -quality 30 ~/sandboxArea/converted/$i; done
and the above command worked and all the files were first reduced in size and then put into the "~sandboxArea/converted" folder
Then I again tried to reduce the quality of images stored at the location
~/sandboxArea/SecondCam
and ran the above command after making the required changes as below
for k in $(ls ~/sandboxArea/SecondCam); do convert $k -quality 30 ~/sandboxArea/convertedB/$k; done
and it gave me the following errors:
convert-im6.q16: no images defined `/home/mohit/sandboxArea/convertedB/IMG_5682.JPG' @ error/convert.c/ConvertImageCommand/3258.
convert-im6.q16: unable to open image `IMG_5683.JPG': No such file or directory @ error/blob.c/OpenBlob/2701.
convert-im6.q16: no images defined `/home/mohit/sandboxArea/convertedB/IMG_5683.JPG' @ error/convert.c/ConvertImageCommand/3258.
convert-im6.q16: unable to open image `IMG_5684.JPG': No such file or directory @ error/blob.c/OpenBlob/2701.
convert-im6.q16: no images defined `/home/mohit/sandboxArea/convertedB/IMG_5684.JPG' @ error/convert.c/ConvertImageCommand/3258.
convert-im6.q16: unable to open image `IMG_5685.JPG': No such file or directory @ error/blob.c/OpenBlob/2701.
convert-im6.q16: no images defined `/home/mohit/sandboxArea/convertedB/IMG_5685.JPG' @ error/convert.c/ConvertImageCommand/3258.
I tried multiple ways of fixing this issue and also checked the official website of imagemagic.org but there is nothing mentioned about this issue.
Is this a bug? As this command worked once but fail to worked again.
Also, I deleted the files that were previously saved in the "converted" folder to check if the command will work again. And it failed there too. So the same command once worked and the other time it didn't.
Can someone please help. I have about 8000+ images with each about 7-9MB and all these images are eating up a lot of space. Just wanted to save some space on my HDD
Thanks in advance. If anyone needs more clarification please do let me know. Thanks
Solution
Here's an easier way to reproduce your problem:
$ ls ~/tmp
foo.jpg
$ convert foo.jpg bar.jpg
convert-im6.q16: unable to open image `foo.jpg': No such file or directory @ error/blob.c/OpenBlob/2874.
convert-im6.q16: no images defined `bar.jpg' @ error/convert.c/ConvertImageCommand/3258.
The issue is that even though you do have a file foo.jpg
on the system, it is in a different directory, so you can't access it without qualifying the name. In this case, you can instead run:
$ convert ~/tmp/foo.jpg c
(success, no output)
Alternatively, you can change the current directory to where foo.jpg
is:
$ cd ~/tmp
$ convert foo.jpg ~/Downloads/bar.jpg
(success, no output)
A better loop would iterate over globs and quote properly to robustly handle spaces and similar in filenames:
for path in "$HOME/sandboxArea/SecondCam"/*
do
convert "$path" -quality 30 "$HOME/sandboxArea/convertedB/${path##*/}"
done
Answered By - that other guy Answer Checked By - David Marino (WPSolving Volunteer)