I noticed that the current re-size function in Open Cart re-sizes the images proportionately but doesn't do a true "crop" so there is excess left over. It's hard to tell because the background color for Open Cart is white...the same background color the function applies to the images. How do I re-size an image but crop the entire image at it's true re sized height and width? Thanks.
This version is refined and does a more logical procedure based on the original images width and height. The GD resizing only leaves excess if the original image is not square, and if the configured admin image setting is not square. This checks the original size and trims excess if NOT SQUARE. Logically, you wouldn't upload a square image ex. 24 X 24 if you later configured the setting in admin>settings>image to 38 X 45. This will allow you to crop it down to a max width and max height while keeping ASPECT RATIO:
The following is for the products on the category listing page category.tpl:
What's the point in all of this you say? Because sometimes you need to have a different background color other than WHITE which is Open Cart default. This allows your images to seamlessly go on any background because there is no excess white anywhere. Yes, if you know what you are doing you can forget all this and just change the RGB to re-size to a different color other than white but that in itself is still not logical.
The following is for the products on the category listing page category.tpl:
Code: Select all
if ($result['image']) {
$oldsize = getimagesize(DIR_IMAGE.$result['image']);
$max_width = (int)160;
$max_height = (int)160;
//get setting sizes
$width = $oldsize[0];
$height = $oldsize[1];
if($width != $height){
$scale = min($max_width/$oldsize[0], $max_height/$oldsize[1]);
// Get the new dimensions
$new_width = ceil($scale*$oldsize[0]);
$new_height = ceil($scale*$oldsize[1]);
$image = $this->model_tool_image->resize($result['image'], $new_width, $new_height);
//else it is square so do nothing.
}else{
$image = $this->model_tool_image->resize($result['image'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
}
} else {
$image = false;
}
$original = $result['original'];
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($result['canvasprice'], $result['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = false;
}
Here is a vQmod that does all that I just described above but better:
http://www.opencart.com/index.php?route ... on_id=7458
http://www.opencart.com/index.php?route ... on_id=7458
Who is online
Users browsing this forum: Semrush [Bot] and 80 guests