如何从图像创建/保存裁剪图像? (将图像转换为base64)

时间:2017-11-22 14:35:07

标签: javascript reactjs react-native

enter image description here

假设我们有两个方形数据

taggedImages: {
  0: {id:0, left:100, top:100, thumbSize:100, type: 'A', seasons: ['All', 'All']},
  1: {id:1, left:200, top:200, thumbSize:100, type: 'B', seasons: ['All', 'All']},
},

我们可以从<Image />创建/保存两个新的<Image />组件吗?

鉴于

  1. 每个方格的左,顶部,宽度,高度
  2. 整个图像的宽度和高度
  3. 我的方法

    1. 不知何故,我将图像缓存到某些路径(file:// blahblah,file:// blahblah2)
    2. 保存时将它们转换为base64。 (我将通过HTTP发送多个图像)
    3. 任何好的方法或想法都将受到高度赞赏

      更新我使用的是React Native

      谢谢

1 个答案:

答案 0 :(得分:1)

对我而言,听起来你想要从现有的Inge裁剪两张图片,对吗? PHP imagecrop可以解决问题。

您可以像这样使用它:

raise IOError("file error")

如果有多张照片,您可以$source = imagecreatefromjpg('/path/to/source.jpg'); $img1 = imagecrop($im, ['x' => 100, 'y' => 100, 'width' => 100, 'height' => 100]); if ($img1 !== FALSE) { imagejpg($img1, '/path/to/square-1.png'); } $img2 = imagecrop($im, ['x' => 200, 'y' => 200, 'width' => 100, 'height' => 100]); if ($img2 !== FALSE) { imagejpg($img2, '/path/to/square-2.png'); } 上传图片。