CURL在上传到Imgur之前调整图像大小

时间:2016-03-06 18:50:34

标签: php curl imgur

我可以在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'];

    }
}

由于

2 个答案:

答案 0 :(得分:0)

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

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

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

答案 1 :(得分:0)

您可以使用image magick调整大小

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