Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

imageMagick convert from a folder to another command in Linux?

I have the two folders under the same level directory folder1 and folder 2 now I try to convert all images in folder1 to folder2 and with same file name. here is what i have now:

 for f in folder1/*.jpg
 do 
       convert $f  -resize 80%X80% +profile "*" -quality 85 folder2/$f
 done

and it throws the following message from each file it tried to convert: convert: unable to open image `folder1/folder2/st-3474827-1.jpg': No such file or directory @ blob.c/OpenBlob/2440.

and I know its directory problem but google for two days already still dont know how to fix it. Can you help me with this?

like image 361
user452187 Avatar asked Dec 16 '22 18:12

user452187


1 Answers

There's two ways you could deal with it.

  1. Use mogrify:

    mogrify -path folder2 -thumbnail 50x50 folder1/*.jpg
    
  2. Use basename:

    for filename in folder1/*.jpg; do
        basename="$(basename "$filename" .jpg)"
        convert "folder1/$basename.jpg" -thumbnail 50x50 "folder2/$basename.jpg"
    done
    

The former option is probably better, but the latter may be clearer.

like image 95
icktoofay Avatar answered Jan 31 '23 04:01

icktoofay