Change white background

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
kxc
Posts: 3
Joined: 2013-12-16T23:56:20-07:00
Authentication code: 6789

Change white background

Post by kxc »

Hello, i'm trying to change image background from #FFFFFF to #F2F2F2, without damaging image. I try to make image transparent (delete all background along the counter and then set my new color bg, but it damage pixels). Then i try to replace all white pixels and replace it with needed color, but it also damage image cause visualy all bg white, but somewhere color like more or less darken. I have image with hard counter, there is example of original image http://rghost.ru/51020287.view020287.view.
With photoshop i create second layer with #F2F2F2 background and use "Multiply" effect for my image, and it's work perfect, but how i can do something like this with ImageMagick. If anybody know, help please :(

There is example like it correctly looks after photoshop http://rghost.ru/51020415.view
I trying to do something like this, dissolve 2 images, by this composite -dissolve 30x70 -gravity South \test.jpg bg.jpg -alpha Set result.jpg but i get this http://rghost.ru/51020432.view :(
Last edited by kxc on 2013-12-17T00:45:44-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Change white background

Post by snibgo »

Multiplying by #f2f2f2 will darken all the pixels. You can easily do this with IM. #f2 = 242. 242/255 = 0.949.

Code: Select all

convert test.jpg -evaluate Multiply 0.949 out.png
snibgo's IM pages: im.snibgo.com
kxc
Posts: 3
Joined: 2013-12-16T23:56:20-07:00
Authentication code: 6789

Re: Change white background

Post by kxc »

snibgo wrote:Multiplying by #f2f2f2 will darken all the pixels. You can easily do this with IM. #f2 = 242. 242/255 = 0.949.

Code: Select all

convert test.jpg -evaluate Multiply 0.949 out.png
Wooow... It's very nice, many thanks to you :) And thank for this very quickly reply. :D
kxc
Posts: 3
Joined: 2013-12-16T23:56:20-07:00
Authentication code: 6789

Re: Change white background

Post by kxc »

Sorry, mby somebody know the best way to do this using PHP ?
I make this with following code

Code: Select all

for ($i = 0; $i < 4; $i++) {
    echo "<pre>";
    exec("convert ".$i.".jpg -evaluate Multiply 0.949 ".$i."_result.jpg");
    echo "</pre>";
}
But mby there is other way, by using Imagick for PHP ?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Change white background

Post by fmw42 »

see http://us3.php.net/manual/en/imagick.evaluateimage.php

but note that Imagick is not very well supported any longer and generally does not speed things up. See
viewtopic.php?f=4&t=16779
Post Reply