Форум АНТИЧАТ

Форум АНТИЧАТ (https://forum.antichat.xyz/index.php)
-   PHP, PERL, MySQL, JavaScript (https://forum.antichat.xyz/forumdisplay.php?f=37)
-   -   Работа с картинками (https://forum.antichat.xyz/showthread.php?t=117996)

.::BARS::. 27.04.2009 15:29

Работа с картинками
 
Столкнулся с такой проблемой....
при загрузки картинки на сервер нужно ее уменьшить в размерах....
уменьшать нужно без потери качества... НЕ резать...
----
просто задаем уменьшение пока 1 из сторон не будет = 220 px ...
у меня выходит тупой обрез картинки по сторонам, а нам нужно уменьшение... во втором случаем у меня скукожило картинку...

----
прошу помочь....

MuXaJIbI4 27.04.2009 16:45

покажи свой скрипт по уменьшению размера картинки

OdaN 27.04.2009 16:58

PHP код:

<?
header
("Content-type: image/jpg");
$newside='220';
$im=imagecreatefromjpeg("patch/image.jpg");
$h=ImageSY($im);
$w=ImageSX($im);

if (
$h $w
$max=$w;
else
$max=$h;

$pers=(($newside/$max));

$new_w=(($w*$pers));
$new_h=(($h*$pers));

$thumb=imagecreatetruecolor($new_w,$new_h);

imagecopyresized($thumb,$im,0,0,0,0,$new_w$new_h$w$h);
imagejpeg($thumb);
imagedestroy($thumb);
?>

Как-то так...

Pashkela 27.04.2009 17:06

PHP код:

<pre>
<?php 
@set_time_limit(0); 
@
ini_set("display_errors","1");
//ini_set('default_charset','UTF-8');
//ini_set('default_charset','windows-1251');

function resize($img$thumb_width$newfilename

  
$max_width=$thumb_width;

    
//Check if GD extension is loaded
    
if (!extension_loaded('gd') && !extension_loaded('gd2')) 
    {
        
trigger_error("GD is not loaded"E_USER_WARNING);
        return 
false;
    }

    
//Get Image size info
    
list($width_orig$height_orig$image_type) = getimagesize($img);
    
    switch (
$image_type
    {
        case 
1$im imagecreatefromgif($img); break;
        case 
2$im imagecreatefromjpeg($img);  break;
        case 
3$im imagecreatefrompng($img); break;
        default:  
trigger_error('Unsupported filetype!'E_USER_WARNING);  break;
    }
    
    
/*** calculate the aspect ratio ***/
    
$aspect_ratio = (float) $height_orig $width_orig;

    
/*** calulate the thumbnail width based on the height ***/
    
$thumb_height round($thumb_width $aspect_ratio);
    

    while(
$thumb_height>$max_width)
    {
        
$thumb_width-=10;
        
$thumb_height round($thumb_width $aspect_ratio);
    }
    
    
$newImg imagecreatetruecolor($thumb_width$thumb_height);
    
    
/* Check if this image is PNG or GIF, then set if Transparent*/  
    
if(($image_type == 1) OR ($image_type==3))
    {
        
imagealphablending($newImgfalse);
        
imagesavealpha($newImg,true);
        
$transparent imagecolorallocatealpha($newImg255255255127);
        
imagefilledrectangle($newImg00$thumb_width$thumb_height$transparent);
    }
    
imagecopyresampled($newImg$im0000$thumb_width$thumb_height$width_orig$height_orig);
    
    
//Generate the file, and rename it to $newfilename
    
switch ($image_type
    {
        case 
1imagegif($newImg,$newfilename); break;
        case 
2imagejpeg($newImg,$newfilename);  break;
        case 
3imagepng($newImg,$newfilename); break;
        default:  
trigger_error('Failed resize image!'E_USER_WARNING);  break;
    }
 
    return 
$newfilename;
}

//Пример вызова

echo resize("dss.png"60"thumb_test4.png"

?>
</pre>



Время: 22:59