Delal jsem neco podobneho. Zkuste si ulozit nasledujici skript jako soubor
onthefly.php
---
<?php
$src_file = $pic;
//$pozX = 142;
//$pozY = 95;
//$quality = 50;
// find the image size
$imginfo = @getimagesize($src_file);
if ($imginfo == NULL)
return false;
// height/width
$srcWidth = $imginfo[0];
$srcHeight = $imginfo[1];
// echo "Original: ";
// echo $src_file;
// echo ": ";
// echo $srcWidth;
// echo "x";
// echo $srcHeight;
// echo "<BR>";
// echo "Zmenseno: ";
//Kontrola, zda nejde o zvetseni
if ($pozX > $srcWidth)
{
if ($pozY > $srcHeight)
{
$sirkaN = round($srcWidth);
$vyskaN = round($srcHeight);
}
else
{
$koef = $srcHeight/$pozY;
$sirkaN = round($srcWidth/$koef,0);
$vyskaN = round($srcHeight/$koef,0);
}
}
else
{
$koef = $srcWidth/$pozX;
$vyskaN = round($srcHeight/$koef,0);
if ($vyskaN > $pozY)
{
//echo "Na vysku! ";
$koef = $srcHeight/$pozY;
$sirkaN = round($srcWidth/$koef,0);
$vyskaN = round($srcHeight/$koef,0);
}
else
{
// echo "Na sirku! ";
$sirkaN = round($srcWidth/$koef,0);
}
}
// echo $sirkaN;
// echo "x";
// echo $vyskaN;
// echo "<BR>";
$src_img = imagecreatefromjpeg($src_file);
// $dst_img = imagecreatetruecolor($destWidth,$destHeight);
// $dst_img = imagecreatetruecolor($sirkaN,$vyskaN);
//$text_color = imagecolorallocate ($im, 233, 14, 91);
//imagestring ($im, 1, 5, 5, "A Simple Text String", $text_color);
//$dest_file = str_replace(".jpg", ".png", $dest_file);
if ($pozadi == 1)
{
$im = @imagecreatetruecolor ($pozX,$pozY)
or die ("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate ($im, 0, 0, 0);
imagecopyresized($im, $src_img, ($pozX-$sirkaN)/2, ($pozY-$vyskaN)/2, 0, 0, $sirkaN,(int)$vyskaN, $srcWidth, $srcHeight);
}
if ($pozadi == 0)
{
$im = @imagecreatetruecolor ($sirkaN,$vyskaN)
or die ("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate ($im, 0, 0, 0);
imagecopyresized($im, $src_img, 2, 2, 0, 0, $sirkaN-4,(int)$vyskaN-4, $srcWidth, $srcHeight);
}
//$grey_shade = imagecolorallocate($im,204,204,204);
//imagefill($im,$sirkaN-100,$vyskaN-30, $grey_shade);
if ($pozadi == 0)
{
$black = imagecolorallocate($im,0,0,0);
$grey_shade = imagecolorallocate($im,204,204,204);
imagefilledrectangle ($im, $sirkaN-405, $vyskaN-15, $sirkaN-2, $vyskaN-2, $grey_shade);
// imagejpeg($im, 'tmp'.$pic, $quality); // Quality z parametru
imagejpeg($im, 'tmp.jpg', $quality); // Quality z parametru
$size = FileSize( 'tmp.jpg');
$sizeo = FileSize($pic);
Imagestring($im,2, $sirkaN-400,$vyskaN-15,"Rozmery:" . $sirkaN . "x". $vyskaN . " Velikost: " . $size . " Kvalita:" . $quality . " Orig.: " . $srcWidth . "x" . $srcHeight . "/". $sizeo . "b", $black);
// Imagestring($im,2, $sirkaN-200,$vyskaN-15,$sirkaN . "x". $vyskaN . " V: " . $size . " Q:" . $quality , $black);
// imagettftext ( resource image, int size, int angle, int x, int y, int col, string fontfile, string text)
//$black = imagecolorallocate ($im, 0, 0, 0);
//$white = imagecolorallocate ($im, 255, 255, 255);
//imagettftext ($im, 20, 0, 10, 20, $white, "arial", "Testing...Omega: Ω");
//imagegif ($im);
//imagedestroy ($im);
// imagejpeg($im, 'tmp'.$pic, $quality); // Quality z parametru
}
if ($pozadi == 1)
{
// imagejpeg($im, 'tmpN'.$pic, $quality); // Quality z parametru
}
//imagejpeg($im, 'tmp.jpg', $quality); // Quality z parametru
//$dummy = unlink('tmp.jpg');
//ImageRectangle($im,0,0,$sirkaN-1,$vyskaN-1,$black);
header("Content-type: image/jpeg");
imagejpeg($im, '', $quality); // Quality z parametru
?>
---
Syntaxe volani pak je z jineho HTML dokumentu napr:
<IMG SRC = onthefly.php?pozX=800&pozY=400&quality=30&pozadi=0&pic=Image-94.jpg>
Ukazkova aplikace bezi (v testovacim provozu) na: http://cestadosveta.wz.cz/php/slides.php