views:

154

answers:

3

I need to rotate some existing JPG images. They have already lost some detail, but I now want to rotate them and lose no further detail.

With a little research, it seems the only lossless Image rotation library for PHP is by using the jPegTran library.

Are there any other options when it somes to doing lossless jpg rotation?

Thanks!

+4  A: 

Would't it be possible to call an external program say losslessrotator by exec('commandline');

Another option would be jpegtran by jpegclub

schoetbi
I would definitely go with this one; PHP is incredibly slow (and this includes its image manipulation libraries) and you'll be better off calling a program that's actually compiled.
NullUserException
I have no issue with calling other libraries. I will give this a try. As long as it works on Linux.
Jon Winstanley
On linux you can use http://linux.die.net/man/1/jpegtran
schoetbi
+1 for suggesting looking outside the PHP sphere - beyond its well-drilled strengths, PHP is not a 100% coverage tool for the web.
Raise
+1  A: 

Couldn't you read the bytes and just do a transformation that would move them into the right position to rotate them?

C Bauer
No you can't. You'd have to do that transformation on a bitmap.
NullUserException
JPG I guess, is compressed?
C Bauer
Yes. JPG, GIF, PNG - they are all compressed.
NullUserException
JPG's compression has a special property that allows lossless rotation. Each 8x8 cell of the image is compressed separately in a way that can be rotated and reordered.
Lou Franco
A: 

JPEG is a lossy format, so the answer is no, you can't create a lossless rotate of JPEG on any application, programming language, or guru meditation.

What you can do, however, is minimize image data loss by using the $quality argument when saving the rotated JPEG, if you're saving it in JPEG format that is. If you're saving it in lossless format, then you've already minimized image data loss.

Example:

$img = imagecreatefromjpeg($file);
$rot = imagerotate($img, 90, 0);
imagejpeg($rot, $output, 100); /* set quality to 100% */
jmz
Sorry, the JPG is already saved so has already lost some detail. I now want to rotate the lossy image but lose no further detail
Jon Winstanley
You'll achieve that with my advice. If you do not need the output to be JPEG, you can use some other lossless format, like png: imagepng($rot, $output);
jmz