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).

  • By "slice" you mean crop? I would've said ImageMagick; are you sure you used it right? Apr 5, 2011 at 12:59
  • Yes, ImageMagick considers it as cropping. Here's what I've used: $ convert source.png -crop 1024x1024 destination.png
    – Eimantas
    Apr 5, 2011 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 5, 2011 at 16:45
  • @fred.bear - yes, that's exactly what i'm looking for.
    – Eimantas
    Apr 5, 2011 at 17:07

2 Answers 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:

WIDTH=`file $FILE | cut -f5 -d" "`
NUMOFSLICES=`echo "scale=2; $WIDTH/$SLICEWIDTH+1" | bc`
for i in `seq $NUMOFSLICES`
    pngtopnm $FILE | pnmcut -left $LAST -width $SLICEWIDTH | pnmtopng > cropped-$FILENOEXT-$i.png
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… :)


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.

  • Thanks for your answer! Will this output subsequence cropped pieces of an image?
    – Eimantas
    Apr 5, 2011 at 15:55
  • I'm not sure what you mean by subsequence cropped pieces. Can you explain?
    – JRW
    Apr 5, 2011 at 15:58
  • If i have image of 2048x1024 - will it output two images of 1024x1024?
    – Eimantas
    Apr 5, 2011 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.