Autor Zpráva
curdto
Profil
Mám tento script na zmenšování obrázků:

<?php
function ErrorImage($string)
{
header ("Content-type: image/png");
$im = imagecreate (300, 50);
$background_color = imagecolorallocate ($im, 200, 200, 200);
$text_color = imagecolorallocate ($im, 233, 14, 91);
imagestring ($im, 5, 5, 5, "Chyba: ".$string, $text_color);
imagepng ($im);
exit();
}

if(file_exists($_GET["filename"]))
$size=getimagesize($_GET["filename"]);

else
ErrorImage("Soubor neexistuje.");

if($_GET["width"]<5)
ErrorImage("Spatna sirka obrazku.");
if($_GET["height"]<5)
ErrorImage("Spatna vyska obrazku.");

switch($size[2])
{
case 1:
$type="gif";
header("Content-type: image/png");
break;
case 2:
$type="jpeg";
header("Content-type: image/jpeg");
break;
case 3:
$type="png";
header("Content-type: image/png");
break;

default:
ErrorImage("Spatny typ obrazku.");
}

$scale_width=$_GET["width"]/$size[0];
$scale_height=$_GET["height"]/$size[1];
$scale=($scale_width <= $scale_height ? $scale_width : $scale_height);
$new_width=ceil($scale*$size[0]);
$new_height=ceil($scale*$size[1]);

$im = imagecreatetruecolor($new_width,$new_height);
switch($type)
{
case "gif":
$res_im=imagecreatefromgif($_GET["filename"]);
break;
case "jpeg":
$res_im=imagecreatefromjpeg($_GET["filename"]);
break;
case "png":
$res_im=imagecreatefrompng($_GET["filename"]);
break;
}

imagecopyresampled($im, $res_im, 0, 0, 0, 0, $new_width+1, $new_height+1, $size[0], $size[1]);

imagedestroy($res_im);
$ciara = imagecolorallocate ($im, 255, 255, 255);
imagerectangle($im, 0, 0,$new_width-1, $new_height-1, $ciara);

switch($type)
{
case "jpeg":
imagejpeg($im);
break;
case "gif":
case "png":
imagepng($im);
break;
}
?>

A v proměnných nastavuji maximální velikost... Nevíte, jak udělat, aby to nebyla maximální, ani minimální, ale aby prostě byla pevná velikost toho obrázku z proměnné?
Joker
Profil
curdto
Co nejjednodušší úprava:
Vymazat:
$scale_width=$_GET["width"]/$size[0];
$scale_height=$_GET["height"]/$size[1];
$scale=($scale_width <= $scale_height ? $scale_width : $scale_height);
$new_width=ceil($scale*$size[0]);
$new_height=ceil($scale*$size[1]);

a místo toho:
$new_width=$_GET["width"];
$new_height=$_GET["height"];
curdto
Profil
Joker
Díky za pomoc :)
Toto téma je uzamčeno. Odpověď nelze zaslat.

0