Jump to content

[SOLVED] Image background Color....Again


Recommended Posts

Months ago, I did *something* to change my images, thumbnails, etc. to a grey background instead of white. After upgrading to PS 1.4.9, everything looked fine until I added a new image. It had the white background. I tried regenerating all thumbnails to make everything grey again. After that, every single image had the white background, or it had disappeared.

 

Now, it seems that a third of my images are missing.

 

To complicate things further, I have been using Cloudcache to serve images, css, etc. I tried clearing all of their cache, which didn't change anything. For now, I disabled their module, hoping that wherever my images are, the cloud cache won't be a factor in finding them.

 

If there is any good news to a third of my site having broken images, I have a complete backup from yesterday, before I upgraded to 1.4.9. The problem is, the img directory in prestashop has so many subfolders of subfolders that I really have no idea what to replace via ftp.

 

If anyone has any ideas, I'm all ears. Once I find my missing pics again, I still have to convert the white background to grey. Thx.

Edited by rturner (see edit history)
Link to comment
Share on other sites

Just throwing out a shot in the dark here.. I had an unrelated image issue with a jpg containing an alpha channel in my order pdf creation. I didnt even know jpg had an alpha channel, I thought that was a png thing. I use fireworks and had gotten the image from my [spam-filter] who used photoshop where I *think* the alpha came from. In any event I tried like hell to get rid of it and ended up having to do a screenshot and then crop that before I could use the image. Like I said.. long-shot.. but maybe your editor is leaving alpha laying around and PS is freaking on it.

 

In any event.. sorry to hear your probs and may the force be with your swift repairs man.

SC

Link to comment
Share on other sites

Thanks, SuperCharlie. I have all my images back after I uploaded the entire img directory from backup. I don't think it's an alpha channel, as they are all the same kind of photoshop images. I could try redoing the new image, but I think the code I had in there to make the backgrounds grey was written over by the upgrade. Now when I put new images in, they all have the white background. I haven't yet figured out how I turned them grey before. At least the site works now :-)

Link to comment
Share on other sites

Yay for working site.. :) It would seem that a global image background thing would require the images to have transparency and show the background.. I would think that modifying the product listing and product detail background area to the appropriate gray color would do what you are looking for as long as the images have the transparency. The only other thing I can think of is an on-the-fly color replacement by a server-side php image module but that would be some tricky stuff that might not have the intended consequences all the time.

Link to comment
Share on other sites

You can change the color of the image background in / images.inc.php.

 

look for the instances where $white is defined and place in your own rgb values.

 

there's also a $transparent that may need altering.

 

Then regenerate thumbnails.

  • Like 2
Link to comment
Share on other sites

Hey Wynn, I'll try that this evening when I can work on the site. I had tried replacing the $white definition earlier, but didn't do anything with a $transparent code. Also, there may be cache/compile or media server issues (as in turning it off before I change images) I need to go over step-by-step. I'll post back if it works. Thanks!

Link to comment
Share on other sites

Okay, Wynn had the solution. All is working now. Thanks, guys. To summarize, when you want a different background color for your images and thumbnails:

 

1- Edit /your_prestashop_directory/images.inc.php

 

2- Find every instance of 255 which defines the white background and replace it with your color. In my case the color was grey and the RBG values in photoshop are 153,153,153

 

3- So, example:

Replace this:

$transparent = imagecolorallocatealpha($destImage, 255, 255, 255, 127);

With this:

$transparent = imagecolorallocatealpha($destImage, 153, 153, 153, 127);

 

There are about 5 sections like that you will have to change from Line 250 or so down.

 

4-It works! And in my case (am I maybe just a teensy gunshy?) I didn't have to regenerate thumbnails to get it to work.

Edited by rturner (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 1 year later...
  • 2 months later...

For Prestashop 1.5.    you have  to  edit  the file classes/ImageManager.php

 

For  example  to change to grey background  change 255,255,255   to  228,228, 228 as shown below:

    $dest_image = imagecreatetruecolor($dst_width, $dst_height);

        // 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, 228, 228, 228, 127);
            imagefilledrectangle($dest_image, 0, 0, $dst_width, $dst_height, $transparent);
        }
        else
        {
            $white = imagecolorallocate($dest_image, 228, 228, 228);
            imagefilledrectangle ($dest_image, 0, 0, $dst_width, $dst_height, $white);
        }

  • Like 1
Link to comment
Share on other sites

For Prestashop 1.5.    you have  to  edit  the file classes/ImageManager.php

 

For  example  to change to grey background  change 255,255,255   to  228,228, 228 as shown below:

    $dest_image = imagecreatetruecolor($dst_width, $dst_height);

 

        // 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, 228, 228, 228, 127);

            imagefilledrectangle($dest_image, 0, 0, $dst_width, $dst_height, $transparent);

        }

        else

        {

            $white = imagecolorallocate($dest_image, 228, 228, 228);

            imagefilledrectangle ($dest_image, 0, 0, $dst_width, $dst_height, $white);

        }

 

Thank you for finding out how to change the background color of product images and thumbnails in prestashop!

 

This, which has a mayor impact on your skin, should be more easily to be modified in the back office. Would love to see that happen in a new version of prestashop. :)

Link to comment
Share on other sites

Ok, you need to change another file in the classes folder too, or new product thumbs still have a white background.

 

In webservice -> WebserviceSpecificManagementImages.php around line 833:

 

 

// Build the image
if (
!($destImage = imagecreatetruecolor($destWidth, $destHeight)) ||
!($white = imagecolorallocate($destImage, 255, 255, 255)) ||

 

 

 
Change the 255's into whatever rgb value you need.
  • Like 1
Link to comment
Share on other sites

  • 3 months later...
×
×
  • Create New...