Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Então pessoal esto com um probleminha aki neste código, pois quando vou salva imagem de um determinado site não da, aparecer um erro, mas fora alguns site a imagem e salva corretamente.
Esse é a imagem que esta dando problema pra salva: http://s.glbimg.com/po/tt/f/original/2013/07/31/battlefield-4-windows-8-xbox-one.jpg
Quando vo salva esta imagem aparecer este erro aki:
PHP Warning: imagecreatefromjpeg() [<a href='function.imagecreatefromjpeg'>function.imagecreatefromjpeg</a>]: gd-jpeg: JPEG library reports unrecoverable error: in E:\home\site\Web\site\editar.php on line 369
PHP Warning: imagecreatefromjpeg() [<a href='function.imagecreatefromjpeg'>function.imagecreatefromjpeg</a>]: '../thumb/battlefield-4-windows-8-xbox-one.jpg' is not a valid JPEG file in E:\home\site\Web\site\editar.php on line 369
PHP Warning: imagesx(): supplied argument is not a valid Image resource in E:\home\site\Web\site\editar.php on line 247
PHP Warning: imagesy(): supplied argument is not a valid Image resource in E:\home\site\Web\site\editar.php line 249
PHP Warning: Division by zero in E:\home\site\Web\site\editar.php on line 251
PHP Warning: imagecreatetruecolor() [<a href='function.imagecreatetruecolor'>function.imagecreatetruecolor</a>]: Invalid image dimensions in E:\home\site\Web\site\editar.php on line 277
PHP Warning: imagecopyresampled(): supplied argument is not a valid Image resource in E:\home\site\Web\site\editar.php on line 279
Aki é o código pra salva imagem:
function resize_relative( $image, $new_width, $new_height )
{
$new_width = ( int ) $new_width;
$new_height = ( int ) $new_height;
$old_width = imagesx( $image );
$old_height = imagesy( $image );
$ratio_orig = ( $old_width / $old_height );
if( $new_width / $new_height > $ratio_orig )
{
$dif_w = ( $new_height * $ratio_orig );
$dif_h = $new_height;
}
else
{
$dif_w = $new_width;
$dif_h = ( $new_width / $ratio_orig );
}
$img = imagecreatetruecolor( $dif_w, $dif_h );
imagecopyresampled( $img, $image, 0, 0, 0, 0, $dif_w, $dif_h, $old_width, $old_height );
return $img;
}
$url_salva = 'http://s.glbimg.com/po/tt/f/original/2013/07/31/battlefield-4-windows-8-xbox-one.jpg';
$ch = curl_init( $url_salva );
curl_setopt( $ch, CURLOPT_HEADER, false );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_BINARYTRANSFER, true );
$image = curl_exec( $ch );
curl_close( $ch );
$dir = '../thumb/';
$filename = $dir . pathinfo( $url_salva, PATHINFO_BASENAME );
$fp = fopen( $filename, 'w' );
fwrite( $fp, $image );
fclose( $fp );
$new_width = 170;
$new_height = 100;
if(pathinfo( $filename, PATHINFO_EXTENSION ) == 'gif'){
$image = resize_relative( imagecreatefromgif( $filename ), $new_width, $new_height );
}elseif(pathinfo( $filename, PATHINFO_EXTENSION ) == 'png'){
$image = resize_relative( imagecreatefrompng( $filename ), $new_width, $new_height );
}else{
$image = resize_relative( imagecreatefromjpeg( $filename ), $new_width, $new_height );
}
$new_dir = '../thumb/';
$new_name = "thumb_$id_a_editar";
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$thumb_name = "thumb_$id_a_editar.$ext";
$filename = $new_dir . $new_name . '.' . pathinfo( $filename, PATHINFO_EXTENSION );
@imagejpeg( $image, $filename, 100 );Carregando comentários...