【问题标题】:Error with blob imageBlob 图像错误
【发布时间】:2023-03-27 22:53:02
【问题描述】:

我正在使用以下代码裁剪图像并收到以下错误。

错误


警告:imagecreatefromstring():数据不在 识别格式 C:\MAMP\htdocs\mike\dist\functions\crop.php 上线 20

警告:需要 imagecopyresampled() 正好 10 个参数,8 个在 C:\MAMP\htdocs\mike\dist\functions\crop.php 上线 21

警告:imagestring() 完全符合 6 个参数,2 个在 C:\MAMP\htdocs\mike\dist\functions\crop.php 上线 22

注意

$img_name 是一个 blob

例如:blob:http%3A//localhost/c1d90080-4603-4aa4-a618-555a70f840dd

date_default_timezone_set("America/New_York");
  $img_name = $_POST['imgname']; //this is an blob
  $cropx = $_POST['crop_X'];
  $cropy = $_POST['crop_y'];
  $cropw = $_POST['cropw'];
  $croph = $_POST['croph'];

  $dst_X = 0;
  $dst_Y = 0;
  $src_X = $cropx;
  $src_Y = $cropy;
  $dst_w = $cropw;
  $dst_h = $croph;
  $src_w = $src_X + $dst_w;
  $src_w = $src_Y + $dst_h;

  $dst_image = imagecreatetruecolor($dst_w, $dst_h);
  $src_image = imagecreatefromstring($img_name);
  imagecopyresampled($dst_image, $src_image, 
                     $dst_X, $dst_Y, 
                     $src_X, $src_Y, 
                     $dst_w, $dst_h
                    );
  imagestring($dst_image, "/dist/cropped.png");

【问题讨论】:

  • 你找到这个答案了吗@saqib ?

标签: php blob


【解决方案1】:

BLOB 通常是图像的二进制数据,从 URL 字符串到文件 URL 是否直接指向图像的位置,因为您可能需要从字符串中解析 URL 并在将其推送到之前使用 file_get_contents($url) imagecreatefromstring

例如:

$img_name = $_POST['imgname'];
$parts = explode(':', $img_name);
$img_string = file_get_contents($parts[1]);

imagecreatefromstring($img_string);

【讨论】:

  • 这在没有“blob:”文件的浏览器中无法打开,因此它显示以下错误 file_get_contents(http%3A//localhost/e2220d4e-c7a2-4096-a04c-b87741b5d591) : 无法打开流: 中没有这样的文件或目录
  • 你可以尝试使用带有 $img_name 的 file_get_contents 吗?
  • imagecreatefromstring 需要具有二进制输入,因此您需要从正在创建的图像中读取原始数据,因此您需要能够从脚本运行的任何位置访问图像,您知道吗如何从服务器环境中访问文件
  • 感谢您的宝贵时间。现在很难找到它,我正在尝试别的东西。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-16
  • 2019-12-09
  • 2016-10-24
  • 1970-01-01
相关资源
最近更新 更多