Output file name

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?".
Post Reply
Thrandur
Posts: 5
Joined: 2018-01-17T06:41:25-07:00
Authentication code: 1152

Output file name

Post by Thrandur »

I am creating thumbnails from images using this comman:

convert * -thumbnail 200x200^ -gravity center -extent 100x100 thumbs/*.png

The output is just as expected :)

In the source folder there are two files a.png and b.jpg and in the output folder the corresponding thumbnails created are a-0.png and a-1.png.

How can I keep the original filenames - and without the numbering?
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Output file name

Post by GeeMack »

Thrandur wrote: 2018-01-17T08:00:20-07:00How can I keep the original filenames - and without the numbering?
It looks like "mogrify" might be the right tool for what you're trying to do. Try this...

Code: Select all

mogrify -thumbnail 200x200^ -gravity center -extent 100x100 -path thumbs *.png
Make sure the directory "thumbs" already exists.
Thrandur
Posts: 5
Joined: 2018-01-17T06:41:25-07:00
Authentication code: 1152

Re: Output file name

Post by Thrandur »

Brilliant !

But now I have a new problem...
...this worked for 66 files out of about 15K!

Running on Windows 10

Would it be better on the Hosting server?
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Output file name

Post by GeeMack »

Thrandur wrote: 2018-01-17T09:03:09-07:00Brilliant !

But now I have a new problem... ...this worked for 66 files out of about 15K!
I don't understand your issue. What sort of error do you get when the "mogrify" command stops running? Also, please let us know which version of ImageMagick you're using.
Thrandur
Posts: 5
Joined: 2018-01-17T06:41:25-07:00
Authentication code: 1152

Re: Output file name

Post by Thrandur »

That is the strange part - no error message.

identify -version
Version: ImageMagick 7.0.6-10 Q16 x64 2017-08-27 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Visual C++: 180040629
Features: Cipher DPC Modules OpenMP
Delegates (built-in): bzlib cairo flif freetype jng jp2 jpeg lcms lqr openexr pangocairo png ps rsvg tiff webp xml zlib
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Output file name

Post by GeeMack »

Thrandur wrote: 2018-01-17T11:27:30-07:00That is the strange part - no error message.
Some things I'd consider would be files IM can't read for some reason, or can't write to, permissions, etc. I'd still expect a warning or error message. Maybe a corrupt input file if it always stops at the same place. Put that 67th image aside and test it alone. I'd also maybe check if there's no space left on the drive or a quota is filled or something similar. I'd still expect some kind of warning messages, so it's a mystery.

There is a newer version of IM available, so maybe there's a bug in the version you're using. Check this link for updates.

I don't know much about the internal workings of the program, so maybe some other folks on the forum here can offer other simple – or not – suggestions.
Thrandur
Posts: 5
Joined: 2018-01-17T06:41:25-07:00
Authentication code: 1152

Re: Output file name

Post by Thrandur »

Thanks GeeMack

A corrupt file could be the cause, but then I have to find out in what order the files are processed by IM or even better the actual file that causes trouble.

An update didn't help :(
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Output file name

Post by fmw42 »

Imagemagick uses the file system to list images to process, which is typically alphabetic order (same as typically is displayed by your OS)

Try adding -print "%f\n" to your mogrify command to get it to list the filenames in order processed to the terminal (or redirect to a file)

Code: Select all

mogrify -thumbnail 200x200^ -gravity center -extent 100x100 -path thumbs -print "%f\n"  *.png
Thrandur
Posts: 5
Joined: 2018-01-17T06:41:25-07:00
Authentication code: 1152

Re: Output file name

Post by Thrandur »

Thanks all :)

This has been an interesting journey of discovery - so I wanted to share some steps:

//Step 1 - List files and find corrupt
identify -regard-warnings *.* >log.txt 2>&1

//Step 2 - Delete corrupt files and file formats you don't plan on using

//Step 3a - Generate thumbnails + list files
mogrify -thumbnail 200x200^ -gravity center -extent 100x100 -print "%f\n" -path thumbs *.png

//Step 3b - Generate thumbnail - all jpg
FOR %a in (*.jpg) DO mogrify %a -thumbnail 200x200^ -gravity center -extent 100x100 -print "%f\n" -path thumbs %a

Generating using the FOR loop seems to work the best, looping over each format in turn.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Output file name

Post by Bonzo »

Off topic: I see you have made use of -print now fmw42 8)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Output file name

Post by fmw42 »

Bonzo wrote: 2018-01-18T13:30:43-07:00 Off topic: I see you have made use of -print now fmw42 8)
I had to, since -format would have to be used twice, once for the file format and the other for the filename. So I just tried using -print rather than -format "%f" -write info:. To my surprise, -print worked in mogrify.
Post Reply