2016-03-06 115 views
0

我可以在将图像发布到imgur之前调整图像大小?我已经测试链接像http://i.imgur.com/XXXXXl.png但我需要调整前CURL在上传到Imgur之前调整图像大小

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']; 

    } 
} 

感谢

回答

0

您可以调整使用难懂的

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

+0

感谢您的回复,我谁可以使用imagick用的file_get_contents? '$ image = new Imagick($ tmpFile); $ image-> resizeImage(400,400); file_get_contents($ image)'? – soooo

+0

检查示例,$ imagick-> getImageBlob()返回转换图像的二进制bolb。 – xvan

相关问题