ImageMagick: possibly OT

Bill Oliver vendor at billoblog.com
Thu Sep 17 17:32:03 UTC 2015


On Thu, 17 Sep 2015, Bill Oliver wrote:

> On Thu, 17 Sep 2015, Timothy Murphy wrote:
>
>>  I want to crop a PNG picture.
>>  I see how to do it with ImageMagick,
>>  once I know the pixel-positions of the corners of the rectangle.
>>
>>  I'm wondering if there is a way of imposing a grid to read these numbers,
>>  either with ImageMagick or some other application that runs under Fedora ?
>> 
>> 
>
> I may not be understanding the problem, but if you just need the four
> corners, e.g. 0,0; 0,1023; 1023,0, 1023,1023 for a 1024 x 1024 image, and you 
> don't want to need to look at the image, try the netpbm library,
> e.g.
>
> $ pngtopnm < tst.png | pnmfile
>
>
> billo
>
>

As an aside, you can then crop it by using pnmcut.

So, for instance, if I wanted to cut a 100 pixel border from an image, I
might write a script that did this:


#! bin/sh

pngtopnm < $1 > tmp.pnm
pnmfile < tmp.pnm > jnk.txt
x=`awk '{print $4}' < jnk.txt`
y=`awk '{print $6}'< jnk.txt`
width=$(( x-100 ))
height=$(( y-100))
pnmcut  50 50 $width $height tmp.pnm > tmp2.pnm
pnmtopng tmp2.pnm > tmp.png
rm tmp.pnm
rm tmp2.pnm
rm jnk.txt

I know that awk is probably not the best thing for this, but I know awk, so...



billo


More information about the users mailing list