在php中以正确的方式保存jpeg图像

在php中以正确的方式保存jpeg图像,php,Php,因此,我使用一个php文件创建了此图像,该文件为我提供了以下链接: image-crop.php?x=179&y=101&w=104&h=104&img=initial-image.jpeg 此图像来自图像裁剪工具: 因此,我想保存此图像,因此我执行以下操作: file_put_contents("image-crop.php?x=179&y=101&w=104&h=104&img=initial-image.jpeg", ""

因此,我使用一个php文件创建了此图像,该文件为我提供了以下链接:

image-crop.php?x=179&y=101&w=104&h=104&img=initial-image.jpeg
此图像来自图像裁剪工具:

因此,我想保存此图像,因此我执行以下操作:

file_put_contents("image-crop.php?x=179&y=101&w=104&h=104&img=initial-image.jpeg", "");
这确实为我提供了文件,但它只能在我的浏览器中查看 当我想使用windows photo的应用程序a打开时,会出现以下错误:

file format not recognized
我试着使用Curl,但它给了我同样的结果

这似乎是图像制作不正确,但我不知道我做错了什么,请帮助

顺便说一句

如果我能让它工作,我想在下面使用图像:

public static function fromPath(string $path): self
{
    return static::fromString(file_get_contents($path));
}

/**
 * Create a new decoder instance from the specified string.
 *
 * @param string $data
 * @return GdDecoder
 */
public static function fromString(string $data): self
{
    if (false === $image = imagecreatefromstring($data)) {
        throw new InvalidArgumentException('Could not read image');
    }

    return new static($image);
}
编辑

只是检查了你是否用记事本打开.jpeg文件,它是空的

编辑

我在图片底部得到如下url:

   var img = $("#cropbox").attr('src');
    var src = 'image-crop.php?x='+size.x+'&y='+size.y+'&w='+size.w+'&h='+size.h+'&img='+img;
    $.ajax({
        type: "POST",
         url: 'testb.php',
         data : {img: src},
         success: function (result) {
               $('p').html(result);
         }
     });
    $("#cropped_img").show();
    $("#cropped_img").attr('src','image-crop.php?x='+size.x+'&y='+size.y+'&w='+size.w+'&h='+size.h+'&img='+img);
var src是指向该文件的精确链接,那么如何以正确的方式保存它呢

编辑 这是image-crop.php

  <?php 
  $img_r = imagecreatefromjpeg($_GET['img']);
  $dst_r = ImageCreateTrueColor( $_GET['w'], $_GET['h'] );

  imagecopyresampled($dst_r, $img_r, 0, 0, $_GET['x'], $_GET['y'], $_GET['w'], $_GET['h'], $_GET['w'],$_GET['h']);

  header('Content-type: image/jpeg');
  imagejpeg($dst_r);

  exit;
  ?>

刚刚解决了我的问题,请将enire路径放在url之后:


此链接可能不适用于您,因为它是一个公司网络。您的URL与文件名不同。它只是将脚本裁剪到要减小的大小的命令。2. <代码>文件内容(“文件名.jpeg”,”)将空内容放在文件中,所以它是空的。3.您的代码太少,无法提供帮助。检查此内容的存储位置(在var或dir中),并将其放置在非空位置string@Justinas我刚刚编辑了我的帖子,展示了我是如何获得图片链接的,以及我是如何显示你的
image-crop.php的裁剪版本的。php
执行一些操作,并执行类似
标题(“Content-Type:image/jpg”)的操作;echo$croppedContent。所以你需要检查
image-crop.php
code你有没有检查过你下载的文件?“无法识别文件格式”看起来不像PHP给出的错误消息itself@Justinas所以我知道image.crop.php。我怎么走得更远?你能进一步解释吗?在URL之后,这在哪里包含完整路径(什么?)?