Jump to content

Change generated product image background


tlman12

Recommended Posts

Is there a way to change the color of the background that is automatically added when an image upload is regnereated and resized?

 

i guess you used to be able to change it in the image.inc.php or something like that but on 1.5.5 it's not there.

 

 

Link to comment
Share on other sites

Hi tlman,

 

This is done in classes/ImageManager.php:

		// If image is a PNG and the output is PNG, fill with transparency. Else fill with white background.
		if ($file_type == 'png' && $type == IMAGETYPE_PNG)
		{
			imagealphablending($dest_image, false);
			imagesavealpha($dest_image, true);
			$transparent = imagecolorallocatealpha($dest_image, 255, 255, 255, 127);
			imagefilledrectangle($dest_image, 0, 0, $dst_width, $dst_height, $transparent);
		}
		else
		{
			$white = imagecolorallocate($dest_image, 255, 255, 255);     <-- change 255,255,255 to colour code you need they are stored in $white
			imagefilledrectangle ($dest_image, 0, 0, $dst_width, $dst_height, $white);   <-- $white is the var holding the colour value
		}

just change the values stored in the variable $white into some other colour.

To easy calculate the RGB codes (255,255,255 = white etc, colours are given in order R(ed),G(reen),B(lue)) see here:

http://www.colorpicker.com/

pick the colour you want, and look at the R, G, B, values given here.

So for pure blue change into:

$white = imagecolorallocate($dest_image, 0, 0, 255);

(N.B. $white is just a variable name, not the colour! ;-) )

 

By the way if you use PNG images, and set the image quality to "use png for all images", (Back office: Preferences->Images)

the background colour of your image will be transparent instead of white, so it just shows the current background colour/image.

post-455771-0-75707900-1380432351_thumb.jpg

 

Hope this helps,

pascal

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Hi tlman,

 

This is done in classes/ImageManager.php:

		// If image is a PNG and the output is PNG, fill with transparency. Else fill with white background.
		if ($file_type == 'png' && $type == IMAGETYPE_PNG)
		{
			imagealphablending($dest_image, false);
			imagesavealpha($dest_image, true);
			$transparent = imagecolorallocatealpha($dest_image, 255, 255, 255, 127);
			imagefilledrectangle($dest_image, 0, 0, $dst_width, $dst_height, $transparent);
		}
		else
		{
			$white = imagecolorallocate($dest_image, 255, 255, 255);     <-- change 255,255,255 to colour code you need they are stored in $white
			imagefilledrectangle ($dest_image, 0, 0, $dst_width, $dst_height, $white);   <-- $white is the var holding the colour value
		}

just change the values stored in the variable $white into some other colour.

To easy calculate the RGB codes (255,255,255 = white etc, colours are given in order R(ed),G(reen),B(lue)) see here:

http://www.colorpicker.com/

pick the colour you want, and look at the R, G, B, values given here.

So for pure blue change into:

$white = imagecolorallocate($dest_image, 0, 0, 255);

(N.B. $white is just a variable name, not the colour! ;-) )

 

By the way if you use PNG images, and set the image quality to "use png for all images", (Back office: Preferences->Images)

the background colour of your image will be transparent instead of white, so it just shows the current background colour/image.

attachicon.gifimage quality.jpg

 

Hope this helps,

pascal

 

Worked perfectly! very informative thank you very much.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...