【问题标题】:CURL Resize image before upload to ImgurCURL 在上传到 Imgur 之前调整图像大小
【发布时间】:2016-06-20 06:03:09
【问题描述】:

我可以在将图像发布到 imgur 之前调整其大小吗?我已经测试过http://i.imgur.com/XXXXXl.png 之类的链接,但之前我需要调整大小

foreach ($_FILES['file']['tmp_name'] as $index => $tmpName) {
    if( !empty( $tmpName ) && is_uploaded_file( $tmpName ) )
    {

        $file = base64_encode(file_get_contents($tmpName));

         $pvars = array(
          'image' => $file,
          'type' => 'base64'
        );

        $timeout = 120;
        $imgurClientID = "xxx";

        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, 'https://api.imgur.com/3/image');
        curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
        curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Client-ID ' . $imgurClientID));
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $pvars);

        $response = curl_exec($curl);
        curl_close($curl);

        $dataImg = json_decode($response, true);
        $link = $dataImg['data']['link'];

    }
}

谢谢

【问题讨论】:

    标签: php curl imgur


    【解决方案1】:

    您可以使用图像魔法调整大小

    http://php.net/manual/imagick.resizeimage.php

    【讨论】:

    • 感谢您的回复,我可以将 imagick 与 file_get_contents 一起使用吗? $image = new Imagick($tmpFile); $image->resizeImage(400, 400); file_get_contents($image)?
    • 查看示例,$imagick->getImageBlob() 返回转换后图像的二进制 bolb。
    【解决方案2】:

    CURL 不是图像处理库。您必须以某种方式处理图像,例如使用 GD 函数:

    http://php.net/manual/en/book.image.php

    您还可以在 Google 上搜索许多免费的图像处理库。

    【讨论】:

      猜你喜欢
      • 2014-12-07
      • 1970-01-01
      • 2011-04-16
      • 2015-12-05
      • 1970-01-01
      • 2016-09-30
      • 2021-11-14
      • 2015-05-02
      • 1970-01-01
      相关资源
      最近更新 更多