Page 1 of 1

Upsizing Undersized Images

Posted: 2011-06-10T11:35:07-07:00
by arcking
Ideally, I'm looking for a way to upsize small images in a folder while leaving images that are larger alone.

Here's what I've come up with (batch file):

Code: Select all

%~d1
CD "%~p1"
MD upsized

FOR %%a in (*.jpg) DO (
	convert %%a	-resize "2400^<"  upsized\%%a
)

PAUSE
It successfully upsizes all of the small images, but also modifies all of the images that are already large enough (they stay the same resolution, but are compressed).

Thanks for your help!

Re: Upsizing Undersized Images

Posted: 2011-06-10T12:27:51-07:00
by fmw42
see note about -quality for jpg images at http://www.imagemagick.org/script/comma ... r5#quality

Your images are probably getting decompressed and then recompressed if you are resaving them as jpg, so you lose quality. Also the quality may not be as high as you started unless you specify the -quality value you want.

Re: Upsizing Undersized Images

Posted: 2011-06-10T12:31:17-07:00
by arcking
fmw42 wrote:see note about -quality for jpg images at http://www.imagemagick.org/script/comma ... r5#quality

Your images are probably getting decompressed and then recompressed if you are resaving them as jpg, so you lose quality. Also the quality may not be as high as you started unless you specify the -quality value you want.
I'm pretty sure that's what's happening, which is why I want to bypass (just skip them) any images that are already large enough - is there any way to do that?

Re: Upsizing Undersized Images

Posted: 2011-06-10T17:06:00-07:00
by fmw42
With your command line, IM will not resize them but will decompress and recompress the jpgs. I don't know any way to avoid IM processing even to read and write it again, except to write a script to compute the image sizes or what not and skip processing them altogether. But perhaps one of the IM developers may have other suggestions.

Re: Upsizing Undersized Images

Posted: 2011-06-10T20:37:03-07:00
by anthony
[quote="arcking"It successfully upsizes all of the small images, but also modifies all of the images that are already large enough (they stay the same resolution, but are compressed).[/quote]

Hmmm it may be that the 'abort' on resize does not preserve the 'taint' flag of the image.
But then I am not certain taint actually aborts a write to the same image.

Hmm quick test using PNG images says it always over writes the image.

Cristy will know more about taint effects.

Re: Upsizing Undersized Images

Posted: 2011-06-11T11:22:35-07:00
by arcking
fmw42 wrote:With your command line, IM will not resize them but will decompress and recompress the jpgs. I don't know any way to avoid IM processing even to read and write it again, except to write a script to compute the image sizes or what not and skip processing them altogether. But perhaps one of the IM developers may have other suggestions.
I was thinking I might have to use a script...any suggestions on what I should do the scripting in?

Am I correct in my understanding that any modification done to a JPEG is lossy? In other words, even if I rewrite the file with "-quality 100" it will have lost some (minute) level of detail (compared to the original). Ultimately a script will probably prove to be worthwhile considering that it's going to have to process over 300,000 images and that I can specify a minimum size that is different from what they'll be resized to.

Re: Upsizing Undersized Images

Posted: 2011-06-11T11:58:00-07:00
by fmw42
arcking wrote:[
I was thinking I might have to use a script...any suggestions on what I should do the scripting in?

Am I correct in my understanding that any modification done to a JPEG is lossy? In other words, even if I rewrite the file with "-quality 100" it will have lost some (minute) level of detail (compared to the original). Ultimately a script will probably prove to be worthwhile considering that it's going to have to process over 300,000 images and that I can specify a minimum size that is different from what they'll be resized to.
Yes, as far as I know jpeg even with -quality 100 with still give some loss. You could use the lossless JP2000 from the jasper library or some other lossless image format, but then the file size will likely be larger.

I script in bash unix. That is pretty much all I know. But you have many options for IM APIs as well.

Here is an example:

#/bin/bash
cd yourdirectory
list=`ls`
for name in $list; do
area=`convert $name -ping -format "%[fx:w*h]" info:`
if [ $area -lt 100000 ]; then
echo "$name $area"
fi
done

put this in a text file and then type

bash textfilename

Re: Upsizing Undersized Images

Posted: 2011-06-14T10:54:29-07:00
by arcking
Thanks for your help! Got a Windows batch script working great - for reference, the meat of the file is posted below:

Code: Select all

SET minsize=2925
SET newsize=3000

SETLOCAL ENABLEDELAYEDEXPANSION

FOR %%A in (*.jpg) DO (
	ECHO %%A
	FOR /F "tokens=* delims=" %%B in ('convert %%A -ping -format %%w info:') Do (
		SET width=%%B
	)
	FOR /F "tokens=* delims=" %%B in ('convert %%A -ping -format %%h info:') Do (
		SET height=%%B
	)
	IF !width! LSS %minsize% (
		IF !height! LSS %minsize% (
			ECHO: - Resized
			ECHO "%%A","Resized" >>upsized\Resize_log_file.csv
			convert %%A   -resize %newsize%x%newsize%  upsized\%%A
		)
	)
	ECHO.
)

PAUSE