bat, jpg to webp

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
caho
Posts: 13
Joined: 2019-06-18T00:29:40-07:00
Authentication code: 1152

bat, jpg to webp

Post 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!
)
caho
Posts: 13
Joined: 2019-06-18T00:29:40-07:00
Authentication code: 1152

Re: bat, jpg to webp

Post by caho »

All photos, but already from the folder Compressed
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: bat, jpg to webp

Post 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"
snibgo's IM pages: im.snibgo.com
caho
Posts: 13
Joined: 2019-06-18T00:29:40-07:00
Authentication code: 1152

Re: bat, jpg to webp

Post 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!!!
caho
Posts: 13
Joined: 2019-06-18T00:29:40-07:00
Authentication code: 1152

Re: bat, jpg to webp

Post 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!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: bat, jpg to webp

Post 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.
snibgo's IM pages: im.snibgo.com
caho
Posts: 13
Joined: 2019-06-18T00:29:40-07:00
Authentication code: 1152

Re: bat, jpg to webp

Post by caho »

now it works, thanks!
caho
Posts: 13
Joined: 2019-06-18T00:29:40-07:00
Authentication code: 1152

Re: bat, jpg to webp

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: bat, jpg to webp

Post by snibgo »

Code: Select all

convert -version
snibgo's IM pages: im.snibgo.com
caho
Posts: 13
Joined: 2019-06-18T00:29:40-07:00
Authentication code: 1152

Re: bat, jpg to webp

Post 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
Post Reply