이 스크립트를 사용하여 원격 이미지를 다운로드하고 크기를 조정합니다. 크기 조정 부분에서 뭔가 잘못되었습니다. 이게 뭐야? 내가 그것을 실행하면원격 이미지 컬링 및 크기 조정
<?php
$img[]='http://i.indiafm.com/stills/celebrities/sada/thumb1.jpg';
$img[]='http://i.indiafm.com/stills/celebrities/sada/thumb5.jpg';
foreach($img as $i){
save_image($i);
if(getimagesize(basename($i))){
echo '<h3 style="color: green;">Image ' . basename($i) . ' Downloaded OK</h3>';
}else{
echo '<h3 style="color: red;">Image ' . basename($i) . ' Download Failed</h3>';
}
}
function save_image($img,$fullpath='basename'){
if($fullpath=='basename'){
$fullpath = basename($img);
}
$ch = curl_init ($img);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$rawdata=curl_exec($ch);
curl_close ($ch);
// now you make an image out of it
$im = imagecreatefromstring($rawdata);
$x=300;
$y=250;
// then you create a second image, with the desired size
// $x and $y are the desired dimensions
$im2 = imagecreatetruecolor($x,$y);
imagecopyresized($im2,$im,0,0,0,0,$x,$y,imagesx($im),imagesy($im));
imagecopyresampled($im2,$im,0,0,0,0,$x,$y,imagesx($im),imagesy($im));
// delete the original image to save resources
imagedestroy($im);
if(file_exists($fullpath)){
unlink($fullpath);
}
$fp = fopen($fullpath,'x');
fwrite($fp, $im2);
fclose($fp);
// remember to free resources
imagedestroy($im2);
}
?>
어떤 오류가 발생합니까? – Merijn
테스트 케이스는 어디에 있습니까? – Greg
다운로드 실패 오류는 – mark