Page 1 of 1
trouble with background in rotated jpg file
Posted: 2008-01-03T09:22:04-07:00
by maceis
Hello together,
I have a jpg image from a digital camera which I want to modify (resizing, border, rotation, shadow) for putting it on the web
The problem is that the background gets slightly different from what I define.
If I save the result in png format the background color is okay but not if I save it in jpg.
How can I create a JPG Image with the exact background color I defined?
I also noticed that the whole image is a little darker if I save it as jpg.
Here is what I am doing:
Code: Select all
convert haus_08.jpg \
-crop 2496x2038+0+0 \
-resize 352x288 +repage \
-bordercolor white -border 6 \
-bordercolor '#999' \
-border 1 \
-background none -rotate 3 \
\( +clone -background black -shadow 60x5+5+5 \) +swap \
-background '#bbddff' -flatten \
haus3.jpg
You can compare the results of png vs jpg with the following two links:
PNG
JPG
The background of the PNG Image is slightly lighter (as the whole image is).
Re: trouble with background in rotated jpg file
Posted: 2008-01-03T11:48:05-07:00
by Bonzo
Have you tried the polaroid operator ?
http://www.imagemagick.org/script/comma ... p#polaroid
Not to many options though and I saved as a png not a jpg.
To be honist both your images looked the same to me
Re: trouble with background in rotated jpg file
Posted: 2008-01-03T13:51:18-07:00
by maceis
The polaroid operator doe not really meet my needs.
The difference is not very big but if I put the image on a background of the same color it is quite remarkable.
Re: trouble with background in rotated jpg file
Posted: 2008-01-03T14:32:13-07:00
by Acestes
Are you looking at them in a browser or an image viewer? If you are viewing them in a browser it could be the way the browser is handling the different image types. I have looked at them both in Firefox and PhotoShop and they both look the same to me.
Re: trouble with background in rotated jpg file
Posted: 2008-01-03T14:43:51-07:00
by Bonzo
I think its best to save them as a png then as you can use a transparent background.
If the backgrounds always come out the same with ImageMagick could you tweek the background colour of the page to match the image ?
I did have a go at modifying the image colours with ImageMagick but it is quite hard to get what you would like;
http://www.rubblewebs.co.uk/imagemagick ... olours.php
Re: trouble with background in rotated jpg file
Posted: 2008-01-03T19:06:52-07:00
by fmw42
jpeg is a lossy (compressed) image format and will not preserve colors exactly. You might try first creating it as a png and then converting to jpeg while setting the quality to 100%, but even that may not help. Also jpg does not allow transparency. So png is your best format.
Re: trouble with background in rotated jpg file
Posted: 2008-01-03T19:45:32-07:00
by anthony
If it must be JPEG your only option is to -flatten your image onto some background color or other image to remove the transparency from the final result.
Re: trouble with background in rotated jpg file
Posted: 2008-01-04T02:34:02-07:00
by maceis
Well, this is exactly what I did (and what has worked well with other images)
Code: Select all
...
-background '#bbddff' -flatten \
result.jpg
But instead of '#bbddff' the background turns out to be '#b0d5fe' and - as I mentioned above - the whole image gets darkened, too.
I also noticed that I do get the correct background color if I process another image with identic commands.
Edit: I also found out that if I convert a png with correct colors to jpg '#bbddff' gets changed to '#b0d5fe'.
If I convert this jpg back to png '#b0d5fe' gets changed to '#bbddff' again.
I have to admit that I am quite confused.
Re: trouble with background in rotated jpg file
Posted: 2008-01-05T15:59:29-07:00
by anthony
maceis wrote:But instead of '#bbddff' the background turns out to be '#b0d5fe' and - as I mentioned above - the whole image gets darkened, too.
I also noticed that I do get the correct background color if I process another image with identic commands.
Edit: I also found out that if I convert a png with correct colors to jpg '#bbddff' gets changed to '#b0d5fe'.
If I convert this jpg back to png '#b0d5fe' gets changed to '#bbddff' again.
Do not be confused. The answer is simply that JPEG is lossy. It does NOT save the colors of any image exactly! That is the tradeoff for getting very large compression ratios. If you need it exact, or need further processing, do not user JPEG, use PNG instead.