Zdravím,
Potrebujem zmenšiť obrázky PNG, keď ale má original presvitné pozadie pri zmenšení zostanie čierne neviete poradiť, ako to vyriešiť? Pozeral som už aj Stackoverflow.com neviem tam zatial nič nájsť.. :)
Ďakujem
function zmensi_obrazok($image_max_width, $image_max_height, $obrazok, $cesta, $nazov)
{
$valid_exts = array("jpg","jpeg","png");
$ext = end(explode(".",strtolower($obrazok[name])));
if($obrazok[size] <= 1024000)
{
if(in_array($ext,$valid_exts))
{
if($ext == "jpg" || $ext == "jpeg")
{
$image = imagecreatefromjpeg($obrazok[tmp_name]);
}
elseif($ext == "png")
{
$image = imagecreatefrompng($obrazok[tmp_name]);
}
list($width,$height) = getimagesize($obrazok[tmp_name]);
$old_width = imagesx($image);
$old_height = imagesy($image);
$scale = min($image_max_width/$old_width, $image_max_height/$old_height);
$new_width = ceil($scale*$old_width);
$new_height = ceil($scale*$old_height);
$tmp = imagecreatetruecolor($new_width,$new_height);
if($ext == "gif" or $ext == "png")
{
imagecolortransparent($tmp, imagecolorallocatealpha($tmp, 0, 0, 0, 127));
imagealphablending($tmp, false);
imagesavealpha($tmp, true);
}
$filename = $cesta.$nazov.".".$ext;
imagecopyresampled($tmp,$image,0,0,0,0,$new_width,$new_height,$width,$height);
imagejpeg($tmp,$filename,100);
return "";
imagedestroy($image);
imagedestroy($tmp);
}
}
}