Discussion:
Image Magick (convert)
Add Reply
Michael F. Stemper
2021-02-14 21:09:07 UTC
Reply
Permalink
I'm converting a web-scraped image from gif to png and cutting its
bottom off (ouch!) at the same time. It seems that convert wants to
be helpful and leaves me not only the part that I want, but the part
that I don't want:

***@host$ ll cur*
-rw-rw-r-- 1 user user 158519 Feb 14 14:19 current.gif
***@host$ convert current.gif -crop "1280x776!" current.png
***@host$ ll cur*
-rw-rw-r-- 1 user user 150582 Feb 14 14:57 current-0.png
-rw-rw-r-- 1 user user 6115 Feb 14 14:57 current-1.png
-rw-rw-r-- 1 user user 158519 Feb 14 14:19 current.gif
***@host$

For now, my script includes:
rm current-1.png
mv current-0.png current.png

A bit less than elegant, but it works.

What I would prefer would be if there was a way to tell convert that:
a. I only want the 1280x776 part
b. I'd like it to use the file name that I specified

Spending some time at the imagemagick page left me none the wiser. There
is so much there that I can't figure out what to look for.

Any gurus out there who can lend a hand?
--
Michael F. Stemper
Outside of a dog, a book is man's best friend.
Inside of a dog, it's too dark to read.
mm
2021-04-03 07:03:03 UTC
Reply
Permalink
  rm current-1.png
  mv current-0.png current.png
A bit less than elegant, but it works.
a. I only want the 1280x776 part
b. I'd like it to use the file name that I specified
----------several files in a directory-------------

#!/bin/bash
for P in *.gif
do
tmp=`basename $P .gif`
cp $P $tmp
convert $tmp -crop 1280x776+0+0 $tmp.png
rm $tmp
done

----------one file as argument---------------------

#!/bin/bash
tmp=`basename $1 .gif`
cp $1 $tmp
convert $tmp -crop 1280x776+0+0 $tmp.png
rm $tmp

--------------------------------------------------

if it works?

Loading...