jquery - 如何将图像裁剪为特定的高度和宽度?
问题描述
为什么我没有得到特定高度和宽度的图像?
假设我将裁剪图像设置为 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',
});
解决方案
您需要免费设置 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',
});
希望对你有帮助
推荐阅读
- sql-server - 获取用于更改主键的动态 SQL
- python - 如何在 gspread python pandas 中使用新值(df_old = 100* 30(已在工作表上)和 df_new= 100*30)的大小更新现有单元格?
- google-apps-script - 谷歌表格 - 删除表单响应以空格开头的行的脚本
- c++ - TensorFlow C API 选择 GPU
- python - 我正在尝试使用 Selenium 和 Python 在 Tradingview 中自动打开图表
- java - Completable 必须在 observable on next 被触发时完成
- java - 我如何更改 android.widget.CheckedTextView 的检查值
- python - ValueError:时间数据“2015 年 5 月 11 日”与格式“%m%y%d”不匹配(匹配)
- sql - SQL Server 按月、日和小时划分多个分区
- javascript - 设置整个 redux 存储数据