【发布时间】:2014-12-01 15:40:00
【问题描述】:
我正在尝试使用调整大小和裁剪脚本 Codrops
这很好,但是如果图像没有填充裁剪区域,脚本会失败并且所有图像都会变黑。
我的想法是先创建一个实心图像,然后将裁剪后的图像应用到顶部。但我很挣扎。
我猜这里的某个地方:
var crop_canvas,
left = $('.size_guide').offset().left - $container.offset().left,
top = $('.size_guide').offset().top - $container.offset().top,
width = $('.size_guide').width(),
height = $('.size_guide').height();
crop_canvas = document.createElement('canvas');
crop_canvas.width = width;
crop_canvas.height = height;
crop_canvas.getContext('2d').drawImage(image_target, left, top, width, height, 0, 0, width, height);
关于如何解决这个问题或尝试不同的解决方案有什么想法吗? 非常感谢
【问题讨论】: