Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9215165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:08:36+00:00 2026-06-18T02:08:36+00:00

I have a freshly compiled libjpeg version 9 and tried running jpegtran.exe in command

  • 0

I have a freshly compiled libjpeg version 9 and tried running jpegtran.exe in command line with the arguments:

.\jpegtran.exe -rotate 180 -outfile test_output1.jpg testimg.jpg

testimg.jpg: before test_output1.jpg: after

As you can see it does rotate the image but it clips it and it’s not put together correctly. The usage.txt file that comes with the package isn’t totally up to date because I had to use the -outfile switch instead of what it says:

jpegtran uses a command line syntax similar to cjpeg or djpeg. On
Unix-like systems, you say:

  • jpegtran [switches] [inputfile] >outputfile

On most non-Unix systems, you say:

  • jpegtran [switches] inputfile outputfile

where both the input and output files are JPEG
files.

To specify the coded JPEG representation used in the output file,
jpegtran accepts a subset of the switches recognized by cjpeg:

  • -optimize Perform optimization of entropy encoding parameters.
  • -progressive Create progressive JPEG file.
  • -arithmetic Use arithmetic coding.
  • -restart N Emit a JPEG restart marker every N MCU rows, or every N MCU blocks if “B” is attached to the number.
  • -scans file Use the scan script given in the specified text file.

See the previous discussion of cjpeg for more details about these
switches. If you specify none of these switches, you get a plain
baseline-JPEG output file. The quality setting and so forth are
determined by the input file.

The image can be losslessly transformed by giving one of these
switches:

  • -flip horizontal Mirror image horizontally (left-right).
  • -flip vertical Mirror image vertically (top-bottom).
  • -rotate 90 Rotate image 90 degrees clockwise.
  • -rotate 180 Rotate image 180 degrees.
  • -rotate 270 Rotate image 270 degrees clockwise (or 90 ccw).
  • -transpose Transpose image (across UL-to-LR axis).
  • -transverse Transverse transpose (across UR-to-LL axis).

Oddly enough (or maybe not), if I execute .\jpegtran.exe -rotate 180 -outfile test_output2.jpg test_output1.jpg I get the original image back without any clipping issues. It’s flipping the clipped parts but just not lining it up right with the rest of the image.

test_output2.jpg: after another rotate 180

I get the same result by executing jpegtran.exe -rotate 90 twice.

Also, I tried it on a larger .jpg file which resulted in the same issue but the file size was 18KB smaller for the output. I imagine the issue is related to this.


Edit – I also found this blurb which seems to describe the problem:

jpegtran’s default behavior when transforming an odd-size image is
designed to preserve exact reversibility and mathematical consistency
of the transformation set. As stated, transpose is able to flip the
entire image area. Horizontal mirroring leaves any partial iMCU
column at the right edge untouched, but is able to flip all rows of
the image. Similarly, vertical mirroring leaves any partial iMCU row
at the bottom edge untouched, but is able to flip all columns. The
other transforms can be built up as sequences of transpose and flip
operations; for consistency, their actions on edge pixels are defined
to be the same as the end result of the corresponding
transpose-and-flip sequence.

The -trim switch works, if you can call it that, and trims out the disorganized data but the image is smaller and lost data.

test_output5.jpg: trimmed output

Adding the -perfect switch which supposedly stops the above from happening results in this: transformation is not perfect for output and no image.

So is it not possible to losslessly rotate a .jpg? I could, myself, go into paint and reconstruct the original image by simply moving the edge lines into their correct place. Is there a method to do this within libjpeg?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:08:37+00:00Added an answer on June 18, 2026 at 2:08 am

    A lossless rotation works with whole DCT blocks contained within the JPEG file. These blocks are always 8×8 or 16×16 pixels (depending on the compression downsampling settings). The file contains a width and height so the extra pixels can be thrown away when the image is decoded, but there’s no way to move the clipping from the right/bottom edge to the left/top edge. The software is doing the best it can with an impossible problem.

    As you’ve discovered the way around this problem is to make the width and height evenly divisible by 16. You’ll find that images from cameras for example will have this property.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a freshly compiled python 3.2.3 on CentOS 6, and I'm having trouble
NUnit is failing in C++/CLI with a System.IO.FileNotFoundException. I have tried my own freshly-created
I have freshly installed Python 3.3 (x64) and PyWin32, and then did the following
I posted this question and have a freshly minted code signing cert from Thawte.
Scenario: I have created a database table. And when I tried to add a
I have freshly installed Ubuntu OS , installed Eclipse and then added Android sdk
I have an RCP product which doesn't run. Then I installed Eclipse freshly, and
I have an application that uses wxWidgets as a the UI framework and compiled
I have freshly installed VS2010 with SP1, and when I try to connect to
I have Eclipse 4.2 (Juno) + PDT 3.1.1 freshly installed and i've selected PHP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.