gpt4 book ai didi

javascript - imagecopyresampled 返回 null

转载 作者:行者123 更新时间:2023-12-02 17:44:15 25 4
gpt4 key购买 nike

我有以下代码:

$fullImg = $_POST['img'];
$avatar_name = $log_username.md5(uniqid()).'_avatar.jpg';
$avatar_path = '../user/'.$log_username.'/';
$avatar_new = $avatar_path.$avatar_name;
$target_h = $target_w = 150;
$x = $_POST['x'];
$y = $_POST['y'];
$w = $_POST['w'];
$h = $_POST['h'];
$qual = 90;

$orig_image = imagecreatefromjpeg($fullImg);
$new_image = imagecreatetruecolor($target_w,$target_h);

imagecopyresampled($new_img,$orig_image,0,0,$x,$y,$target_w,$target_h,$w,$h);

imagejpeg($new_image,$avatar_new,$qual);

我的 error_log 中有一个错误,内容如下:

Warning: imagecopyresampled() expects parameter 1 to be resource, null given

我猜这与我的 $_POST['img'] 变量是完整网址有关:

http://domain.com/images/image.jpg

我已在 php.ini 文件中将 allow_url_fopen 设置为 1。我认为这可能会解决它。

它只是一个完整的网址,因为它被 js 读取为 var img = _('uloadedImg').src; 并且尽管将其设置为 ../images/image .jpgvar img = _('uloadedImg').src; 仍然返回完整的网址。

有没有办法从图像中获取src而不用js中的完整url?或者我的脚本还有什么问题吗?

最佳答案

存在类型错误,您指定的是 $new_img 而不是 $new_image:

$new_image = imagecreatetruecolor($target_w,$target_h);
imagecopyresampled($new_img,$orig_image,0,0,$x,$y,$target_w,$target_h,$w,$h);
^

尝试以下:

imagecopyresampled($new_image,$orig_image,0,0,$x,$y,$target_w,$target_h,$w,$h);

关于javascript - imagecopyresampled 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21906791/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com