weixin_33721427 2012-04-22 02:27 采纳率: 0%
浏览 34

用jQuery裁剪图像

I'm looking to have users upload an image and then it will be cropped to a set size. What I'd like to have happen is essentially a div that's set to the specific crop size and the image inside that box. The user would then be able to slide the image around and whatever was visible in that div is what the image would be cropped to.

All of the jquery plugins I've come across simply let the user move a selection box around the full image and not move the image behind the selection box. Does this sort of thing exist and have I just missed that plugin?

Basically it would be like the thumbnail editor in Facebook where you drag your image around in the thumbnail-sized box.

  • 写回答

3条回答 默认 最新

  • weixin_33725239 2012-04-22 02:45
    关注

    You don't really need a plugin for that. This can be done by vanilla jQuery and CSS by setting the background-position value.

    <div id="CroppedImageDiv"></div>
    <script type="text/javascript">
        function cropImage(imgUrl, cropWidth, cropHeight, cropStartX, cropStartY) {
            var bgPos = cropStartX + "px " + cropStartY + "px";
            $('#CroppedImageDiv').width(cropWidth).height(cropheight).css('background-position', bgPos);
            $('#CroppedImageDiv').css('background-url', imgUrl);
        }
    </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!