trouble with background in rotated jpg file

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
maceis

trouble with background in rotated jpg file

Post 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).
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: trouble with background in rotated jpg file

Post by Bonzo »

Have you tried the polaroid operator ? http://www.imagemagick.org/script/comma ... p#polaroid
Image

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 :shock:
maceis

Re: trouble with background in rotated jpg file

Post 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.
Acestes

Re: trouble with background in rotated jpg file

Post 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.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: trouble with background in rotated jpg file

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: trouble with background in rotated jpg file

Post 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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: trouble with background in rotated jpg file

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
maceis

Re: trouble with background in rotated jpg file

Post 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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: trouble with background in rotated jpg file

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply