Autor Zpráva
nantarus
Profil *
jak na zmenseniny obrazku?

- pres formular ukladam fotografie v rozliseni 800*600, ale chci aby se zaroven udelala zmensenina a ulozila, jak na to?

Predem diky vsem
BaTeCzKo
Profil
V php je na to funkce imagecopyresized nebo imagecopyresampled (tahle zmenšeniny i vyhlazuje, tak to vypadá lépe - ale je to pomalejší).

Dá se to použít nějak takto - toto je skript, který podle parametru path navrátí zpět už zmenšený obrázek. Používá se takto: <img src="nahled.php?path=obrazek.jpg">

Zde je:

<?php
$outputwidth=148;
$outputheight=116;

$path=$_GET['path'];
$path="../../".$path;
$suffix=strrpos($path, ".");
$suffix=substr($path, $suffix+1);

if(file_exists($path)){

list($width, $height)=getimagesize($path);
$thumb=imagecreatetruecolor($outputwidth,$outputheight);

switch($suffix){
case "jpg": $source=@imagecreatefromjpeg($path); break;
case "jpeg": $source=@imagecreatefromjpeg($path); break;
case "png": $source=@imagecreatefrompng($path); break;
case "gif": $source=@imagecreatefromgif($path); break;
default: exit;
}

imagecopyresized($thumb, $source, 0, 0, 0, 0, $outputwidth, $outputheight, $width, $height);


/*odeslani a ukonceni*/
header("Content-type: image/jpeg");
imagejpeg($thumb);
imagedestroy($thumb);

}
?>
minimal
Profil *
samotna funkcia getimagesize() vracia pole informacii o obrazku, ktore sa da vyuzit na "switchovanie" jpg,png,gif.

Sample Array of getimagesize():

(
[0] => 253
[1] => 384
[2] => 2
[3] => width="253" height="384"
[bits] => 8
[channels] => 3
[mime] => image/jpeg
)

kde index [2] moze nadobudat hodnoty "1" [gif] "2" [jpg] "3" [png] , co sa da pouzit nasledujucim sposobom:

$image_size=getimagesize($source_filename);

switch($image_size['2']):
case'1':$im_in=imagecreatefromgif($source_filename);break;
case'2':$im_in=imagecreatefromjpeg($source_filename);break;
case'3':$im_in=imagecreatefrompng($source_filename);break;
default: return false;
endswitch;
minimal
Profil *
uvedenu kostrukciu pouzivam vo funkcii na vytvaranie "thumbnailov" , preto je tam to:
default: return false;
peta
Profil
minimal ja mam taky konstrukci, ale ja si do promenne priradim odkaz na funkci :)
switch($type1)
{
case 'png': $x = "ImageCreateFromPNG"; $imgIn = function_exists($x) ? $x : -1; break;
case 'jpg': $x = "ImageCreateFromJPEG"; $imgIn = function_exists($x) ? $x : -1; break;
case 'gif': $x = "ImageCreateFromGIF"; $imgIn = function_exists($x) ? $x : -1; break;
case 'bmp': $x = "ImageCreateFromWBMP"; $imgIn = function_exists($x) ? $x : -1; break;
case 'xbm': $x = "ImageCreateFromXBM"; $imgIn = function_exists($x) ? $x : -1; break;
case 'xpm': $x = "ImageCreateFromXPM"; $imgIn = function_exists($x) ? $x : -1; break;
default: return FALSE; break;
}
if ($imgIn!=-1)
{
switch($type2)
{
case 'jpg': $x = "ImageJPEG"; $imgOut = function_exists($x) ? $x : -1; break;
case 'png': $x = "ImagePNG"; $imgOut = function_exists($x) ? $x : -1; break;
case 'gif': $x = "ImageGIF"; $imgOut = function_exists($x) ? $x : -1; break;
case 'bmp': $x = "ImageWBMP"; $imgOut = function_exists($x) ? $x : -1; break;
case 'xbm': $x = "ImageXBM"; $imgOut = function_exists($x) ? $x : -1; break;
default: return FALSE; break;
}

// Output
if ($type2=='jpg' || $type2=='png')
{$imgOut($image2,$photo2,85);} // save image, jpg/png quality
else {$imgOut($image2,$photo2);} // save image

Mozna by to slo jeste nejak zmensit s tim function-exist. To pouzivam zas pro pripad, kdy neni instalovana GD knihovna, tak mne cela funkce zmenseni obrazku vyhodi false a toto false potom zpracuji pouze presunutim souboru (cili aby se tak ci tak nahral obrazek na server)

http://www.volny.cz/peter.mlich/www.htm#msub11
- www.volny.cz/peter.mlich (zdroj: ppgal.rar)
- interval.cz PHP galerie obrazku
minimal
Profil *
ja by som sa pytal iba raz na zaciatku:

if(extension_loaded('gd')==true)
{
// komandy
}
else{echo'gd not loaded';}
minimal
Profil *
druha vec je, aka verzia gd je k dispozicii (moze to byt rozne):

gd_info();

sample:

array(12) {
["GD Version"]=>
string(27) "bundled (2.0.28 compatible)"
["FreeType Support"]=>
bool(true)
["FreeType Linkage"]=>
string(13) "with freetype"
["T1Lib Support"]=>
bool(true)
["GIF Read Support"]=>
bool(true)
["GIF Create Support"]=>
bool(true)
["JPG Support"]=>
bool(true)
["PNG Support"]=>
bool(true)
["WBMP Support"]=>
bool(true)
["XPM Support"]=>
bool(false)
["XBM Support"]=>
bool(true)
["JIS-mapped Japanese Font Support"]=>
bool(false)
}
Toto téma je uzamčeno. Odpověď nelze zaslat.

0