Resize Images from a file

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?".
vipvicks71
Posts: 22
Joined: 2016-09-26T10:27:07-07:00
Authentication code: 1151

Resize Images from a file

Post by vipvicks71 »

I have a file called filelog.txt
In that file, I have path of all images which needs to be resized.

Example of file:

/var/www/vhosts/abc.com/httpdocs/image/catalog/family-matching-outfits/HEHelloEnjoyFamilyMatchingOutfits2016autumncasualmotheranddaughterclothesLooseT-shirtdotpantsclothingset-1000001500105-0.jpeg
/var/www/vhosts/abc.com/httpdocs/image/catalog/family-matching-outfits/FamilyLookNavyStripedSummerCottonShort-sleeveT-shirtsTeesMatchingClothingOutfitsForMotherDaughterAndFatherSon-32484948616-0.png
/var/www/vhosts/abc.com/httpdocs/image/catalog/family-matching-outfits/BearLeader2016NewSpringampAutumnStyleFamilyMatchingOutfitsMotherAndDaughterFallFullBalckStripedDressFreeShipping-32562503223-2.jpeg

Commad I am using for single file: convert /var/www/vhosts/abc.com/httpdocs/image/catalog/Sliver-Faux-Suede-High-Heel-Boots-shoes16082406-1500.jpeg -quality 50 /var/www/vhosts/abc.com/httpdocs/image/catalog/Sliver-Faux-Suede-High-Heel-Boots-shoes16082406-1500.jpeg

Its working fine of single file from command line. But I want to execute full list from a file. How would I do that?
Last edited by vipvicks71 on 2016-09-26T10:36:33-07:00, edited 1 time in total.
vipvicks71
Posts: 22
Joined: 2016-09-26T10:27:07-07:00
Authentication code: 1151

Re: Resize Images from a file

Post by vipvicks71 »

I just want to change the quality of each file. I dont want to use any other feature of convert command. I want the filename to be same as old. No change in filename too.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resize Images from a file

Post by fmw42 »

What is your IM versions and platform? Please always provide that when asking questions, since syntax varies.

The easiest thing would be to move a copy of all those images into one folder and use mogrify. See http://www.imagemagick.org/Usage/basics/#mogrify. It will automatically loop over each image in the directory and apply -quality 50

Code: Select all

cd to your directory
mogrify -format jpg -quality 50 *
Be sure you make copies of your files. Otherwise, use the -path argument to put the results into a new (already created) folder.

Alternately, you will have to write a shell script to read your text file and process it row by row for each image and do your above convert command.

This will write over your originals with the same name after processing. So best to make copies.

Unix syntax:

Code: Select all

list=`cat files.txt`
for img in $list; do
convert $img -quality 50 $img
done
vipvicks71
Posts: 22
Joined: 2016-09-26T10:27:07-07:00
Authentication code: 1151

Re: Resize Images from a file

Post by vipvicks71 »

I have images under catalog directory. But catalog directory has sub-directories.
catalog/WOMEN'S BOOTS/
catalog/TABLET PC ACCESSORIES/
and so on.

I wont be able to "cd" into all directory. I have path of each images which needs to be converted, stored in filelog.txt
So I can use this unix syntax directly?

list=`cat filelog.txt`
for img in $list; do
convert $img -quality 50 $img
done
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resize Images from a file

Post by fmw42 »

If your paths are full paths from root or relative paths from where you run the script, then that should work fine. But it will overwrite your images. I do not recommend that unless you have backups. You would be better off creating a new directory and writing the results to that new directory.

Code: Select all

list=`cat filelog.txt`
for img in $list; do
convert $img -quality 50 path2/newdirectory/$img
done
I would also recommend that you make a new directory with a few images in it and create a new filelog.txt for that as a test case to be sure it is working, before you run your full set of data.
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Resize Images from a file

Post by GeeMack »

fmw42 wrote:The easiest thing would be to move a copy of all those images into one folder and use mogrify. See http://www.imagemagick.org/Usage/basics/#mogrify. It will automatically loop over each image in the directory and apply -quality 50
The list of images can be read from a file using the "@" prefix on most recent versions of IM. If I make a text file named "filelist.txt" containing the names of all my images, including the full paths, I can run this command using ImageMagick 6.9.3 on Windows 10...

Code: Select all

mogrify -quality 50 @filelist.txt
Using ImageMagick 7.0.3, I would use this command...

Code: Select all

magick mogrify -quality 50 @filelist.txt
That will, of course, overwrite all the original images. Standard cautions apply.

ETA: Also, if any of the image filenames on the list contain spaces (or possibly other special characters) they will have to be surrounded by quote marks.
vipvicks71
Posts: 22
Joined: 2016-09-26T10:27:07-07:00
Authentication code: 1151

Re: Resize Images from a file

Post by vipvicks71 »

@GeeMack

filelist.txt contains:

`/var/www/vhosts/addiszone.com/httpdocs/image/catalog/Womens - Dresses - Ali/wholesale2015newolivestrapVnecksexybodyconcelebritypartypencilwomenbandageDress-32522073354-1.jpeg`
`/var/www/vhosts/addiszone.com/httpdocs/image/catalog/Womens - Dresses - Ali/2016WomenSummerBodyconDressVintagePrintedSexySleevelessPartyVestidoDeFestaFemaleClothingALineDressesPRDRS96-32659027524-1.jpeg`
`/var/www/vhosts/addiszone.com/httpdocs/image/catalog/decorative films/customstickerlogotextprintedstickerlabeltagsadhesivesmalllabelscolororclear1000pcslot-681136713-2.jpeg`
`/var/www/vhosts/addiszone.com/httpdocs/image/catalog/decorative films/StocklaserholographicstickersVOIDIFREMOVED10x30mmwarrantystickers2000pcslot-32342432305-8264.jpeg`
`/var/www/vhosts/addiszone.com/httpdocs/image/catalog/decorative films/NewArrivalWaterproofFrostedHomePrivacyBathroomRoomGlassFilmWindowSticker45200cmBlackWhite-32651121379-0.jpeg`


And it does nothing. I have imagemagick version:
Version: ImageMagick 6.7.2-7 2016-06-16 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP

So I am running: mogrify -quality 50 @filelist.txt
But does nothing. No image is resized.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Resize Images from a file

Post by snibgo »

What are those backticks for?
snibgo's IM pages: im.snibgo.com
vipvicks71
Posts: 22
Joined: 2016-09-26T10:27:07-07:00
Authentication code: 1151

Re: Resize Images from a file

Post by vipvicks71 »

@snibgo

which backsticks?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Resize Images from a file

Post by snibgo »

The backticks at the start and end of every filename.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resize Images from a file

Post by fmw42 »

He is asking about
`/var/www/vhosts/addiszone.com/httpdocs/image/catalog/Womens - Dresses - Ali/wholesale2015newolivestrapVnecksexybodyconcelebritypartypencilwomenbandageDress-32522073354-1.jpeg`
The backtics at the start and end of the file. You probably want single or double quotes which are different from backtics

This is a backtic `

This is a single quote '

This is a double quote "

My script has backtics for the unix syntax. File paths should have quotes not backtics to avoid problems with spaces in filenames.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resize Images from a file

Post by fmw42 »

P.S. In my script and when using @filename.txt, you probably need to put the full path to filename.txt. Otherwise it is expecting the file to be in the directory from which you are running the script or mogrify command.
vipvicks71
Posts: 22
Joined: 2016-09-26T10:27:07-07:00
Authentication code: 1151

Re: Resize Images from a file

Post by vipvicks71 »

I am using double quote "

"/var/www/vhosts/addiszone.com/httpdocs/image/catalog/clothing-sets/1sethotfashionshortSleeveBabyboyGirlClothingsuitsChildrenClothingSetNewbornBabyClothesCottonBabysetszie70100-32691919189-3371.jpeg"

But still no effect. I am specifying the full path of the filename.txt
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Resize Images from a file

Post by GeeMack »

vipvicks71 wrote:I have imagemagick version:
Version: ImageMagick 6.7.2-7 2016-06-16 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP

So I am running: mogrify -quality 50 @filelist.txt
But does nothing. No image is resized.
Your version of IM is very, very old. I'm not sure when reading a list of images from a text file was introduced. It may not be a feature in your 6.7.2 version. Any way about it I'd recommend you bring your IM up to date if you can. Current binary installations for some systems and links to source code can be found HERE. I'm not the best one to offer advice on installing it on a *nix system, but there are people on this forum who can point you in the right direction for that. Otherwise you'll probably have to write a small script with a "for" loop as fmw42 suggested.
vipvicks71
Posts: 22
Joined: 2016-09-26T10:27:07-07:00
Authentication code: 1151

Re: Resize Images from a file

Post by vipvicks71 »

If I have to write a small script then could anyone help me with the script?
What would be the file name with extension and what would be the contents?
Post Reply