在客户端裁剪和调整图像大小

发布于 2024-09-10 06:01:45 字数 74 浏览 4 评论 0原文

是否可以在客户端 PC 上使用客户端选择的图像,而无需将图像上传到服务器。

如果可以,什么网络编程语言可以做到这一点?

Is it possible to work with client chosen images on client PC without uploading image to server.

If yes, what web programming language can do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

花心好男孩 2024-09-17 06:01:45

您可以使用 HTML5 Canvas,无需使用插件等。

加载图像,更改画布大小并绘制图像。还可以将结果提取为 dataUrl。

<!DOCTYPE HTML>
<html>
  <head>
    <style>
      body { margin: 0px; padding: 0px; }
    </style>
  </head>
  <body>
    <canvas id="myCanvas" width="578" height="200"></canvas>
    <script>
      var canvas = document.getElementById('myCanvas');
      var context = canvas.getContext('2d');
      var imageObj = new Image();

      imageObj.onload = function() {
        // draw cropped image
        var sourceX = 150;
        var sourceY = 0;
        var sourceWidth = 150;
        var sourceHeight = 150;
        var destWidth = sourceWidth;
        var destHeight = sourceHeight;
        var destX = canvas.width / 2 - destWidth / 2;
        var destY = canvas.height / 2 - destHeight / 2;

        context.drawImage(imageObj, sourceX, sourceY, sourceWidth, sourceHeight, destX, destY, destWidth, destHeight);
      };
      imageObj.src = 'http://www.html5canvastutorials.com/demos/assets/darth-vader.jpg';
    </script>
  </body>
</html>

所有功劳都归于:

http://www.html5canvastutorials.com/tutorials/ html5-canvas-image-crop/

You can use HTML5 Canvas, no need to use plugins or such.

Load the image, change the canvas size, and draw image. It's also possible to extract the result as a dataUrl.

<!DOCTYPE HTML>
<html>
  <head>
    <style>
      body { margin: 0px; padding: 0px; }
    </style>
  </head>
  <body>
    <canvas id="myCanvas" width="578" height="200"></canvas>
    <script>
      var canvas = document.getElementById('myCanvas');
      var context = canvas.getContext('2d');
      var imageObj = new Image();

      imageObj.onload = function() {
        // draw cropped image
        var sourceX = 150;
        var sourceY = 0;
        var sourceWidth = 150;
        var sourceHeight = 150;
        var destWidth = sourceWidth;
        var destHeight = sourceHeight;
        var destX = canvas.width / 2 - destWidth / 2;
        var destY = canvas.height / 2 - destHeight / 2;

        context.drawImage(imageObj, sourceX, sourceY, sourceWidth, sourceHeight, destX, destY, destWidth, destHeight);
      };
      imageObj.src = 'http://www.html5canvastutorials.com/demos/assets/darth-vader.jpg';
    </script>
  </body>
</html>

All credit goes to:

http://www.html5canvastutorials.com/tutorials/html5-canvas-image-crop/

猫烠⑼条掵仅有一顆心 2024-09-17 06:01:45

这也可以使用 jQuery、MooTools、Prototype 和 script.aculo.us 等 javascript 库来完成:

http://www.bitrepository.com/image-cropping-with-jquery-mootools-prototype-scriptaculous.html

This can also be done with javascript libraries like jQuery, MooTools, Prototype and script.aculo.us:

http://www.bitrepository.com/image-cropping-with-jquery-mootools-prototype-scriptaculous.html

晌融 2024-09-17 06:01:45

这只能通过 FlashSilverlight 或自定义 Plugin/ActiveX 来完成,具体取决于目标浏览器。

This can only be done with Flash, Silverlight or a custom Plugin/ActiveX depending on the target browser.

情话墙 2024-09-17 06:01:45

如果您正在寻找通过 javascript 实现的图像裁剪器,请查看:https://github.com/supnate/icropper 。它提供了用于裁剪但不真正裁剪图像的用户界面。

If you are looking for a image cropper by javascript, take a look at: https://github.com/supnate/icropper . It provides the user interface for cropping but not real cropping the image.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文