3

I'm looking for a oneliner command that would slice an image into given proportions.

Say input would be filename and slice dimensions. Are there any standard command-line tools for this? I tried ImageMagick to no avail since it garbled my image immensely (it's big, mostly transparent, png).

Eimantas
  • 1,486
  • 3
  • 23
  • 31
  • By "slice" you mean crop? I would've said ImageMagick; are you sure you used it right? – Michael Mrozek Apr 05 '11 at 12:59
  • Yes, ImageMagick considers it as cropping. Here's what I've used: $ convert source.png -crop 1024x1024 destination.png – Eimantas Apr 05 '11 at 13:17
  • @Eimantas.. I'm a bit unsure of what you actually want...but based on what you wrote in a comment to JRW's answer. It seems that you want to divide your original image into two seperate smaller images... That would mean cropping the image two times.. once for the first section, and then again for the second section.... Maybe there is something which will do it in a single pass... (I don't know of anything but someone else may)... Is what I just described actually what you want? ie.. a program which will cut up a picture into two (or more) sections in a single command? – Peter.O Apr 05 '11 at 16:45
  • @fred.bear - yes, that's exactly what i'm looking for. – Eimantas Apr 05 '11 at 17:07

2 Answers2

2

I know that question is little old, but I wrote script that is using JRW solution. Script is splitting image file into series of images of given size:

#!/bin/bash
FILE=$1
FILENOEXT=${FILE%.*}
SLICEWIDTH=$2
WIDTH=`file $FILE | cut -f5 -d" "`
NUMOFSLICES=`echo "scale=2; $WIDTH/$SLICEWIDTH+1" | bc`
for i in `seq $NUMOFSLICES`
do
    LAST=$(($SLICEWIDTH * $i - $SLICEWIDTH))
    pngtopnm $FILE | pnmcut -left $LAST -width $SLICEWIDTH | pnmtopng > cropped-$FILENOEXT-$i.png
done
pngtopnm $FILE | pnmcut -left $LAST | pnmtopng > cropped-$FILENOEXT-$i.png

Argument one is filename and second width of chunk. In most cases the script return error on last chunk, but after that last chunk is cropped outside loop again and everything is ok… :)

Anthon
  • 79,293
pbm
  • 25,387
0

netpbm tools can do this. If you are talking about cropping it:

$ pngtopnm image.png | pnmcut -width 500 -height 500 | pnmtopng > image_cropped.png

If you want to scale it use pnmscale.

JRW
  • 357