Rotate keeping quality

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
myspacee
Posts: 153
Joined: 2007-06-14T02:09:35-07:00

Rotate keeping quality

Post by myspacee »

Hello,
i'm building a Imagemagick php service for my lan users.

I want to allow, via Browser, image rotation that rotate image one step at time (+1% | -1%)
but after few rotations image result very degraded.

Is there any way (or script strategy) to keep quality rotation after rotation ?

thank you for any help,
m.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Rotate keeping quality

Post by snibgo »

You are not using lossy compression, such as jpeg, I hope.

Are you:
1. Rotating original by 1 degree, than rotating that by another degree, etc, or

2. Keeping the original, rotating it by 1 degree, then rotating the original by 2 degrees, etc?
snibgo's IM pages: im.snibgo.com
myspacee
Posts: 153
Joined: 2007-06-14T02:09:35-07:00

Re: Rotate keeping quality

Post by myspacee »

Hello,
I'm using only png for my site and all conversions.

Case 1. Rotating original and ovewrite it with rotated image, then return to user for further steps.

After rotation, image is inscribed in white square so i trim white board in excess.
This causes a false zoom effect that ruins image after 5/6 rotations.

I think to script: keeping original, save user preferences and apply wanted rotations always on original image.
But i'm forced to rethink php UI if choose this scenario.

Anyway to rotate without big loss of quality?

Thank you,
M.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Rotate keeping quality

Post by snibgo »

myspacee wrote:After rotation, image is inscribed in white square so i trim white board in excess.
This causes a false zoom effect that ruins image after 5/6 rotations.
I don't understand. Can you show examples? Perhaps the solution is not to trim each time.

Any operation like rotating or resizing will mangle pixels. There is no escaping this. The trick is to minimise the number of operations. Sometimes, operations can be done on large images but small versions are shown to the user.
snibgo's IM pages: im.snibgo.com
myspacee
Posts: 153
Joined: 2007-06-14T02:09:35-07:00

Re: Rotate keeping quality

Post by myspacee »

my PHP script isn't so easy to show here, it's module called by other one.

But i can summarize in this way:

Code: Select all

copy original.png 11.png /y

cconvert 11.png -rotate 1% zz.png
copy zz.png 11.png /y
cconvert 11.png -rotate 1% zz.png
copy zz.png 11.png /y
cconvert 11.png -rotate 1% zz.png
copy zz.png 11.png /y
cconvert 11.png -rotate 1% zz.png
copy zz.png 11.png /y
cconvert 11.png -rotate 1% zz.png
copy zz.png 11.png /y
cconvert 11.png -rotate 1% zz.png
copy zz.png 11.png /y
cconvert 11.png -rotate 1% zz.png
copy zz.png 11.png /y
cconvert 11.png -rotate 1% zz.png
copy zz.png 11.png /y
cconvert 11.png -rotate 1% zz.png
copy zz.png 11.png /y
cconvert 11.png -rotate 1% zz.png
copy zz.png 11.png /y
cconvert 11.png -rotate 1% zz.png
copy zz.png 11.png /y
cconvert 11.png -rotate 1% zz.png
copy zz.png 11.png /y
cconvert 11.png -rotate 1% zz.png
copy zz.png 11.png /y
All start from uploaded image. this image, after rotation, overwrite original.
In above example i don't trim to show 'tunnel zoom' effect.

m.
Last edited by myspacee on 2014-06-04T14:55:13-07:00, edited 1 time in total.
holden
Posts: 79
Joined: 2013-02-07T08:22:57-07:00
Authentication code: 6789

Re: Rotate keeping quality

Post by holden »

The only way you are going to be able to do this nicely is to do each rotation from the base image, not from the previously rotated image.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Rotate keeping quality

Post by anthony »

Every type of distortion will degrade the image in some way.

The only manipulations that do not are simple cuts, crops, move (integer only) flips, flops etc...
See Simple Distotions
http://www.imagemagick.org/Usage/warping/#simple

All other types will degrade the image.. It is a fact due to the nature of the 'raster' storage, which is itself a degradion of the original source (real life or mathematical construct) of the image. Of course the higher the resolution the less degrading you would get even from the original.

The act of saving images in a raster format or worse a JPG lossy format (which is itself a image distortion, transforming it into a fourier frequency space), is itself a degrading process.


As such the rule of thumb with most image manipulation is... start with the most undistorted image you have, and try to minimise the total number of distortion steps applied. One very complex distion systems can apply hundreds of distortions all in a single step, and thus minimise the total degrading to that of a single step.

In your case always distort from the first original image, using the total amount of rotation the user has specified to generate that image.

This problem is also talked about in an example on generating a image of a stack of rotated images..
See last example in the section...
http://www.imagemagick.org/Usage/thumbnails/#polaroid
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply