Zadejte hledaný výraz...

Převod png obrázku

Petr Vacek
verified
rating uzivatele
14. 1. 2010 01:10:46
takže pro kontrolu, tohle :
function resizeImage($source, $destination = NULL,$wdt, $height = NULL){
if(empty($height)){
// Height is nit set so we are keeping the same aspect ratio.
list($width, $height) = getimagesize($source);
if($width > $height){
$w = $wdt;
$h = ($height / $width) * $w;
$w = $w;
}else{
$w = $wdt;
$h = $w;
$w = ($width / $height) * $w;
}
}else{
// Both width and Height are set.
// this will reshape to the new sizes.
$w = $wdt;
$h = $height;
}
$source_image = @file_get_contents($source) or die('Could not open'.$source);
$source_image = @imagecreatefromstring($source_image) or die($source.' is not a valid image');
$sw = imagesx($source_image);
$sh = imagesy($source_image);
$ar = $sw/$sh;
$tar = $w/$h;
if($ar >= $tar){
$x1 = round(($sw - ($sw * ($tar/$ar)))/2);
$x2 = round($sw * ($tar/$ar));
$y1 = 0;
$y2 = $sh;
}else{
$x1 = 0;
$y1 = 0;
$x2 = $sw;
$y2 = round($sw/$tar);
}
$slate = @imagecreatetruecolor($w, $h) or die('Invalid thumbnail dimmensions');
imagealphablending($slate, false);
imagesavealpha($slate, true);
imagecopyresampled($slate, $source_image, 0, 0, $x1, $y1, $w, $h, $x2, $y2);
// If $destination is not set this will output the raw image to the browser and not save the file
if(!$destination) header('Content-type: image/png');
@imagepng($slate, $destination, 75) or die('Directory permission problem');
ImageDestroy($slate);
ImageDestroy($source_image);
if(!$destination) exit;
return true;
} nefunguje ... a zdrojový obrázek je skutečně průhledný ??
14. 1. 2010 01:10:46
https://webtrh.cz/diskuse/prevod-png-obrazku/strana/2#reply437071
Petr
verified
rating uzivatele
(132 hodnocení)
14. 1. 2010 01:17:20
Napsal jsem PM.
14. 1. 2010 01:17:20
https://webtrh.cz/diskuse/prevod-png-obrazku/strana/2#reply437070
Petr Vacek
verified
rating uzivatele
14. 1. 2010 02:03:04
Takže pro všechny: chyba je ve funkci imagepng, kde rozsah komprese je 0 až 9 a ne 75 .
funkční kod:
function resizeImage($source, $destination = NULL,$wdt, $height = NULL){
if(empty($height)){
// Height is nit set so we are keeping the same aspect ratio.
list($width, $height) = getimagesize($source);
if($width > $height){
$w = $wdt;
$h = ($height / $width) * $w;
$w = $w;
}else{
$w = $wdt;
$h = $w;
$w = ($width / $height) * $w;
}
}else{
// Both width and Height are set.
// this will reshape to the new sizes.
$w = $wdt;
$h = $height;
}
$source_image = @file_get_contents($source) or die('Could not open'.$source);
$source_image = @imagecreatefromstring($source_image) or die($source.' is not a valid image');
$sw = imagesx($source_image);
$sh = imagesy($source_image);
$ar = $sw/$sh;
$tar = $w/$h;
if($ar >= $tar){
$x1 = round(($sw - ($sw * ($tar/$ar)))/2);
$x2 = round($sw * ($tar/$ar));
$y1 = 0;
$y2 = $sh;
}else{
$x1 = 0;
$y1 = 0;
$x2 = $sw;
$y2 = round($sw/$tar);
}
$slate = @imagecreatetruecolor($w, $h) or die('Invalid thumbnail dimmensions');
imagealphablending($slate, false);
imagesavealpha($slate, true);
imagecopyresampled($slate, $source_image, 0, 0, $x1, $y1, $w, $h, $x2, $y2);
// If $destination is not set this will output the raw image to the browser and not save the file
if(!$destination) header('Content-type: image/png');
imagepng($slate,$destination) or die('Directory permission problem');
ImageDestroy($slate);
ImageDestroy($source_image);
if(!$destination) exit;
return true;
}
resizeImage('http://www..cz/obrazky/globus.png', null, 80);
14. 1. 2010 02:03:04
https://webtrh.cz/diskuse/prevod-png-obrazku/strana/2#reply437069
experimentoval sem a pomohlo me
imagecolortransparent($slate,0);
13. 2. 2010 11:52:32
https://webtrh.cz/diskuse/prevod-png-obrazku/strana/2#reply437068
Pro odpověď se přihlašte.
Přihlásit