首页 > 解决方案 > 如何将图像裁剪为特定的高度和宽度?

问题描述

为什么我没有得到特定高度和宽度的图像?

假设我将裁剪图像设置为 width=308 & height=200,它返回 308 X 308。如果我设置 width=200 & height=308,它返回 308 x 308。它返回高度和宽度的最大尺寸。我该如何解决这个问题?

我正在使用cropper.js

if (cropper) {
    canvas = cropper.getCroppedCanvas({
        width: 308, // here set  width 
        height: 200, // here set height 
        imageSmoothingEnabled: false,
        imageSmoothingQuality: 'high',
        fillColor: '#fff',
});

标签: jquerycropperjs

解决方案


您需要免费设置 aspectRatio,如下代码:

if (cropper) {
    canvas = cropper.getCroppedCanvas({
    width: 308, // here set  width 
    height: 200, // here set height
     aspectRatio: "free", // or Free or 0
    imageSmoothingEnabled: false,
    imageSmoothingQuality: 'high',
    fillColor: '#fff',
});

希望对你有帮助


推荐阅读