0

I'm using the resize function in OpenCart , but it's resizing the image whit white spaces in it's top and bottom. I'm not sure, but it looks like, that the resize function is watching only the width, and then mesuring the height.

if (!empty($product_info) && $product_info['image'] && file_exists(DIR_IMAGE . $product_info['image'])) {
        $this->data['thumb'] = $this->model_tool_image->resize($product_info['image'], 100, 100);
    } else {
        $this->data['thumb'] = $this->model_tool_image->resize('no_image.jpg', 100, 100);
    }

This is the code i'm using, nothing much . The width of the image is how I'm setting it, in my case 100px. The width is being setted 100px - to, but it's showing like 20px on top and 20px on bottom , white space.

4

1 回答 1

0

原始图像尺寸比(宽高比)是多少?如果它是 1(假设原始图像是 500px 宽和高),那么应该没有空白。如果比率大于 1,则宽度大于高度(假设为 700px*500px),并且在调整图像大小后,图像顶部和底部的空白区域会被填充。当然,如果比率小于 1,则宽度小于高度(比如说 500 像素*700 像素),您会在图像的左侧和右侧看到空白区域。我在这里没有 OpenCart 资源,但是在调整大小时搜索裁剪参数(或裁剪能力) - 如果它存在然后使用它 - 它将保留生成的图像没有空白,并将较小的尺寸调整为您的设置,而更大的被裁剪了...

于 2012-06-08T10:39:24.090 回答