Post by hcamelion » Wed Aug 19, 2009 3:21 am

I am wondering how cached images work. I set my popup product images to 900x900 then I noticed that it adds white space to the image if it is not 900x900 rather then just resize by width only. For example if a photo is 1000x600 open cart will make it 900x900 if you set that in the admin instead of something like 900x550 if it were to resize by width only while keeping the aspect ratio. Maybe the settings page should have a "resize by" setting. Resize by width, height, both or best fit.

Now I am trying to change the size on the settings page but I guess after the images have been cached you can no longer change them. Is there any way to delete the cache and have it rebuilt other then re-uploading all the photos in the store.

Henry Weismann
877.44.MY.WEB (877.446.9932)
We can help with your Opencart Site - Opencart Web Developer

Image


User avatar
New member

Posts

Joined
Mon Jul 27, 2009 3:14 am
Location - Albany, NY, USA

Post by Daniel » Wed Aug 19, 2009 3:59 am

what happens is the system checks which file is newer. the cached version or the main image. if the main image is newer it makes a new cache and overwrites the old one.

OpenCart®
Project Owner & Developer.


User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm

Post by Qphoria » Wed Aug 19, 2009 10:06 pm

hcamelion wrote:I am wondering how cached images work. I set my popup product images to 900x900 then I noticed that it adds white space to the image if it is not 900x900 rather then just resize by width only. For example if a photo is 1000x600 open cart will make it 900x900 if you set that in the admin instead of something like 900x550 if it were to resize by width only while keeping the aspect ratio. Maybe the settings page should have a "resize by" setting. Resize by width, height, both or best fit.
It should already be keeping the best aspect ratio. It you upload a 300x800 image and then a 800x300 image
It will pad whitespace on the sides of the first one to make it square
It will pad whitespace on the top and bottom of the second one to make it square.
The idea here is to make all images look the same on the store front so they aren't all different sizes making your page all janky.
Its just using the normal php resizing features used in "imagecreatefromjpg" built in function. So it's a standard function.
Now I am trying to change the size on the settings page but I guess after the images have been cached you can no longer change them. Is there any way to delete the cache and have it rebuilt other then re-uploading all the photos in the store.
As Daniel said, if the image is newer it will regenerate. But if you want to regenerate them without uploading new files, simply goto your ftp and delete all the image files from the image/cache folder

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by kdmp » Thu Aug 20, 2009 3:16 am

Just to add to this...

If I delete what is in my cache - it never comes back.

Does OC generate those cache files when they are requested? I just tested your instructions out in 1.3.2 and when I deleted everything (mind you this is a fresh install of OC 1.3.2 with the image folder restored from previous version). I called the 'frontpage' and no product images appear. I log in to my server through SSH and there are no files present in the cache directory. The cache directory has the proper permissions.

Kevin Davidson
Purolator Shipping Module
Canpar Shipping Module
VQMod - Paypal Transaction ID to Payment Details


Active Member

Posts

Joined
Thu Jun 04, 2009 10:40 am
Location - Ontario, Canada

Post by Qphoria » Thu Aug 20, 2009 3:48 am

They are generated the first time they are loaded, yes.

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by kdmp » Thu Aug 20, 2009 6:46 am

Qphoria,

Thanks, my case it was my fault. I didn't set my log file. After I set a name for my log file it started to work. I didn't realize that it was required at the time for testing.

Thanks!

Kevin Davidson
Purolator Shipping Module
Canpar Shipping Module
VQMod - Paypal Transaction ID to Payment Details


Active Member

Posts

Joined
Thu Jun 04, 2009 10:40 am
Location - Ontario, Canada

Post by hcamelion » Thu Aug 20, 2009 7:00 am

Yes, I did realize that the cache rebuilds itself and it only was not working because I tried a sized of "900xnothing". I took a look at the image_resize function in the image helper. I understand why uniform sizes on thumbnails is important but on the larger pictures it ends up making them quite smaller if they are not exactly that size. For example I have an artist who wants to show their artwork which has writing on it. All the artwork are canvas prints roughly 900x600. Some other products are not the same size.

When I upload a 900x600 photo the photo will be padded with white space to make it 900x900. Then when the user clicks on the photo thickbox makes it quite smaller because it is so tall when really it should have been only 600px tall or smaller. This makes the artwork unreadable because when padded the artwork is 400x400 in thick box. I did change the size to 900x600 on the settings page and on my resolution monitor the photos are now a nice 800px wide. If there were a resize by drop down on the image settings users can choose the behavior of the resizing at least on the large photos.

Henry Weismann
877.44.MY.WEB (877.446.9932)
We can help with your Opencart Site - Opencart Web Developer

Image


User avatar
New member

Posts

Joined
Mon Jul 27, 2009 3:14 am
Location - Albany, NY, USA

Post by Bryan76 » Tue Jan 19, 2010 9:01 pm

I"m not sure if this is what you're looking for or not, but I rewrote the resize function of the Image class. It will now create an image with the aspect ratio of the original with no added "letterboxing."

As others noted however, this may screw up the alignment of your catalog. You'll need to fix this in your theme. I did it because I wanted to put a drop shadow on my images.

system/library/image.php

Code: Select all

    public function resize($width = 0, $height = 0) {
    	if (!$this->info['width'] || !$this->info['height']) {
			return;
		}

		$xpos = 0;
		$ypos = 0;

		$scale = min($width / $this->info['width'], $height / $this->info['height']);
		
		if ($scale == 1) {
			return;
		}
		
		$new_width = (int)($this->info['width'] * $scale);
		$new_height = (int)($this->info['height'] * $scale);			
		$xpos = (int)(($width - $new_width) / 2);
		$ypos = (int)(($height - $new_height) / 2);

		$image_old = $this->image;
		$this->image = imagecreatetruecolor($new_width, $new_height);
		
		//$background = imagecolorallocate($this->image, 255, 255, 255);
		//imagefilledrectangle($this->image, 0, 0, $width, $height, $background);
	
		imagecopyresized($this->image, $image_old, 0, 0, 0, 0, $new_width, $new_height, $this->info['width'], $this->info['height']);
		imagedestroy($image_old);

		$this->info['width']  = $new_width;
		$this->info['height'] = $new_height;
    }

Newbie

Posts

Joined
Tue Jan 19, 2010 6:46 am

Post by dantheman50_98 » Sun Oct 31, 2010 10:03 pm

Hi,

I've used this code in system/library/image.php and it has worked, so I now have no added white space which is great. However, the images appear rather jagged now. Have you got any idea why this could be?
I'm using v.1.4.91 by the way. I'm also using the watermark mod, so I had to modify the image.php file in that if itmakes any difference.

Thanks,
Dan

Active Member

Posts

Joined
Sat Sep 18, 2010 2:18 am

Post by dragonxeon » Sun Apr 10, 2011 4:25 am

To fix the jagged issue change this line

imagecopyresized($this->image, $image_old, 0, 0, 0, 0, $new_width, $new_height, $this->info['width'], $this->info['height']);

with this line

imagecopyresampled($this->image, $image_old, 0, 0, 0, 0, $new_width, $new_height, $this->info['width'], $this->info['height']);


Basically you want it to resample the image not use resized

Newbie

Posts

Joined
Sun Apr 10, 2011 4:23 am

Post by dantheman50_98 » Sun Apr 10, 2011 8:05 pm

Oh great, thanks. I'll bear that in mind if I use opencart again.

Active Member

Posts

Joined
Sat Sep 18, 2010 2:18 am

Post by merrydukaan » Thu Jan 26, 2012 7:08 pm

Hi I am on latest version of OC and got the same problem. dragonxeon's solution of replacing with 'imagecopyresampled' is already part of default code, tried deleting image cache too! Any ideas?
Someone?

>> search before you post and [solved] when solved
>>Opencart v1.5.1.3, php 5.1.6, Apache/2.2.3 (CentOS)


New member

Posts

Joined
Sun Jan 01, 2012 3:26 pm


Post by kathylene » Thu Feb 02, 2012 10:35 pm

I am using v1.5.1.3 I changed the code as Bryan76 and dragonxeon suggested and it worked perfectly. I did go through and deleted all the cached image thumbnails that had already been made (/image/cache/data).

I have been trying for quite sometime to get the white letterbox effect to not display since I have a black background. Thanks to the both of you!

Newbie

Posts

Joined
Thu Feb 02, 2012 10:32 pm

Post by ijmilton » Sun Feb 05, 2012 10:58 am

Hello,

New to OpenCart and this forum.

First, thank you very much for making this. It works great!

Second, I converted it to vqmod and here it is :)

Attachments


Newbie

Posts

Joined
Sun Feb 05, 2012 10:51 am

Post by FCWC » Tue Sep 11, 2012 2:33 am

Tx for this.
Using the VQMod - makes it simple!
Now 2 more things. If my image has a transparent background it is turning it black. Fix?

And 2nd - how to auto center images?

New member

Posts

Joined
Tue Jul 31, 2012 3:17 am
Who is online

Users browsing this forum: No registered users and 46 guests