views:

148

answers:

5

Hello. Is it possible to blend the left, right and bottom sides of an image into a color?
Lets say, I want the image to be blended into the color "#F0F0F0". I want the image to appear as an actual part of the background, so I thought it would look cool if it was blended in. Thanks.

+1  A: 

You would have to manipulate the pixeldata of the image to achieve this but once you have that covered its not really a problem. Take the color value of the pixel and blend it with your blendcolor. There are some pretty standard maths that can do it fairly well such as this algorithm value1 + (value2 - value1) * amount often used in pixelshaders when doing multi-texturing.

As others have said image libraries for php such as GD helps out with the data manipulation of the image as you won't have to decode and encode it yourself

Jonas B
+1  A: 

You can do this by using an image-manipulation library like ImageMagick or GD. I found this page where the author uses a gradient to perform blending using GD.

You can also try using Imagick::colorizeimage

UPDATE

Based on your screenshot, I don't see why you couldn't do what you wanted to with just straight HTML+CSS. You can either use a transparent PNG or you can use -moz-opacity, opacity or filter:alpha in your CSS (Cross-browser Transparency via CSS).

Vivin Paliath
Transparent `png` is the only way. If he gives it a `background-color` and then makes it partially opaque, it's going to make the content opaque as well. To OP: Make sure you give us as much info as you can to begin with. There may be ways to skin that cat that you hadn't even conceived of.
dclowd9901
That's right - I keep forgetting about that!
Vivin Paliath
@dclowd9901, Yeh sorry for the lack of info. I will make sure my next question is explained further. +1
Joey Morani
Looking forward to more :)
dclowd9901
+2  A: 

If this is just for a webpage this is possible using basic HTML+CSS. Just like you said, you could use a PNG as a layover (via a carefully positioned <div>) on your background.

Otherwise, look into the ImageMagick Libraries for PHP, as they'll let you programmatically create a blended image like you describe. (Imagick::colorizeImage)

Jweede
+1  A: 

I don't know what you need exactly, but using a semi-transparent png as an overlay you can do a lot as well without the need to manipulate your original images.

jeroen
A: 

i suggest you use verot's upload php class. It contains all currently available serverside manipulation functions dealing with image (rotate, tint, frame color, background color, etc.).

See this sample code:

$foo->image_resize          = true;
$foo->image_ratio_fill      = 'R';
$foo->image_y               = 150;
$foo->image_x               = 100;
$foo->image_background_color = '#FF00FF';
$foo->image_rotate          = '90';
pixeline
Nothing can contain all available serverside manipulations as you can decode and manipulate the image data yourself in any possible way you want however illogical, irrational or unusual :) You could basically re-write a photoshop filter for php (minus native api function-calls towards photoshops api, but you could rewrite those algorithms as well)
Jonas B
ok thanks for the correction. Still, this class offers a lot of built-in image processing facilities.
pixeline