OS X: How to perform a lossless crop of a JPEG image?

5,275

Solution 1

I use Xee. It is so much better than preview for images (IMHO); especially since you can traverse images within the same folder by clicking the arrow buttons. All of the button short cuts are reprogrammable.

It supports lossless cropping and rotation. Just see the webpage.

If you like it, buy milksnake to help the developer out - I did.

Solution 2

This command worked for me:

jpegtran -crop WxH+X+Y infile.jpg outfile.jpg

While perhaps not lossless I found FFmpeg to also do quite well:

ffmpeg -i infile.jpg -filter crop=W:H:X:Y -qmax 1 outfile.jpg

Solution 3

Based on this answer, I can suggest using the command-line tool jpegtran, the GUI-based Jpegcrop Windows program, or one of the many programs based on IJG jpegtran code (although not all of them support cropping).

Share:
5,275

Related videos on Youtube

GJ.
Author by

GJ.

Updated on September 18, 2022

Comments

  • GJ.
    GJ. almost 2 years

    I'm looking for a simple way to losslessly crop JPEGs on Mac OS X.

    Particularly, is there some way to get Preview to perform a lossless crop?

  • Matt M.
    Matt M. almost 13 years
    Doesn't sound very lossless, once you convert back to JPEG format.
  • stack
    stack almost 13 years
    @Matt There is currently nothing in the question that indicates that the result has to be JPEG. Only that the cropping action should be lossless and that ideally the cropping action should be performed in Preview. As I understand it - converting the image first to a lossless format such as TIFF is the only way not to loose any more data. See the answer from MrHelpYou for further explanation on why this is the case.
  • Matt M.
    Matt M. almost 13 years
    Well, this is completely wrong. Lots of software supports lossless cropping, rotating, and sometimes even editing of JPEGs, just not Preview.
  • skub
    skub almost 13 years
    This will happen with any image compression. What your suggesting is the equivalent of repeatedly copying a copy of a copy on a imaging machine.
  • stack
    stack almost 13 years
    @Matt My bad - I now realise that lossless JPEG editing is possible (just not in Preview). I'll change my answer so that it does give a more accurate answer.
  • Eroen
    Eroen over 12 years
    No, fancy algorithms have been developed to crop and rotate jpegs, look here. Obviously it is not losselss wrt the original source, but wrt the previous generation jpeg. Don't worry, I would never have guessed anybody would have done that until I googled it just now.
  • Fred
    Fred about 8 years
    I've never seen ffmpeg suggested as an image editing tool, haha. Interesting. But yes, that's not lossless. jpegtran is.
  • Júda Ronén
    Júda Ronén about 7 years
    It seems the correct (current?) syntax is jpegtran -crop WxH+X+Y infile.jpg > outfile.jpg. The above results in an error message: only one input file.
  • Knocks X
    Knocks X over 2 years
    Xee hasn't been updated in years and is no longer functional on newer versions of MacOS. The bugs prevent it from viewing images correctly.
  • skub
    skub over 2 years
    theunarchiver.com/xee - Version 3.5.4 released 21 Dec 2021. The best place to discuss application bugs is with the software developer.