Page 1 of 1

bat, jpg to webp

Posted: 2019-07-09T00:17:10-07:00
by caho
Hello!

I have a file that converts all photos to the "Compressed" folder. Tell me, please, how can I add a command to this file so that all the photos are converted to webp?

Code: Select all

echo Compress all JPG in a Directory:
echo %Source%
if not exist Compressed mkdir Compressed
for %%i in (*.jpg) do (
	convert ^
	-quality 88 ^
	-filter Lanczos ^
	-sampling-factor 4:4:4 ^
	-define jpeg:dct-method=float ^
	-thumbnail 4100x ^
	"%%i" ".\Compressed\%%~ni-JPG.jpg"
	echo  JPG done!
)

Re: bat, jpg to webp

Posted: 2019-07-09T00:18:44-07:00
by caho
All photos, but already from the folder Compressed

Re: bat, jpg to webp

Posted: 2019-07-09T03:58:46-07:00
by snibgo
Operations such as "-thumbnail" should come after reading the input, not before it.

If you want webp instead of jpg, just change the extension of the output filename.

If you want webp as well as jpg, then insert a "+write" operation, eg so the end of the convert command is:

Code: Select all

...
 "%%i" ^
-thumbnail 4100x ^
+write ".\Compressed\%%~ni-JPG.webp" ^
".\Compressed\%%~ni-JPG.jpg"

Re: bat, jpg to webp

Posted: 2019-07-09T04:46:20-07:00
by caho
snibgo wrote: 2019-07-09T03:58:46-07:00 Operations such as "-thumbnail" should come after reading the input, not before it.
am i doing wrong? please tell me how?

snibgo wrote: 2019-07-09T03:58:46-07:00 If you want webp as well as jpg, then insert a "+write" operation, eg so the end of the convert command is:
happened! thank!!!

Re: bat, jpg to webp

Posted: 2019-07-09T04:54:01-07:00
by caho
that's right?

Code: Select all

convert ^
	-quality 88 ^
	-filter Lanczos ^
	-sampling-factor 4:4:4 ^
	-define jpeg:dct-method=float ^
	"%%i" ^
	-thumbnail 300x ^
	+write ".\Compressed\%%~ni-w300.webp" ^
	".\Compressed\%%~ni-w300.jpg"
	echo  JPG and WebP 300px done!

Re: bat, jpg to webp

Posted: 2019-07-09T05:13:00-07:00
by snibgo

Code: Select all

am i doing wrong? please tell me how?
What version of IM are you using?

IM expects the operations to be specified in the order you want them performed. For example: read the image, then make it a thumbnail, then write it. We can't make a thumbnail before we have read an image.

Modern versions of IM will check that you haven't asked to operate on images that don't yet exist, and will raise an error for your original command.

Older versions of IM will rearrange the order of operations, so will accept your original command.

Re: bat, jpg to webp

Posted: 2019-07-09T05:23:11-07:00
by caho
now it works, thanks!

Re: bat, jpg to webp

Posted: 2019-07-09T05:25:32-07:00
by caho
snibgo wrote: 2019-07-09T05:13:00-07:00 What version of IM are you using?
how can I find out the version IM?

Re: bat, jpg to webp

Posted: 2019-07-09T05:27:56-07:00
by snibgo

Code: Select all

convert -version

Re: bat, jpg to webp

Posted: 2019-07-09T05:37:59-07:00
by caho
snibgo wrote: 2019-07-09T05:27:56-07:00

Code: Select all

convert -version
Version: ImageMagick 6.9.9-37 Q16 x64 2018-03-04