Autor | Zpráva | ||
---|---|---|---|
Actimel Profil * |
#1 · Zasláno: 25. 6. 2008, 12:26:13
Dobrý den,
používám následující skritp pro úpravu obrázků, tedy změnu jejich velikosti. Výsledky jsou však poněkud kostrbaté. Napadá někoho jak docílit lepších výsledků? Toto téma je reakcí na diskusi http://diskuse.jakpsatweb.cz/index.php?action=vthread&forum=2&topic=76 531 , kde je rovněž odkaz na stránky používající tento skript. Děkuji <?php /* * Editing of images using PHP GD Library * Author: Jiri Thiemel <Thiemel.Jiri@gmail.com> */ function create_image($file, $new_width, $new_height) { # If GD Library is not installed if (!function_exists("gd_info")) send_file($file); # Get new sizes if (!is_numeric($new_width)) unset($new_width); if (!is_numeric($new_height)) unset($new_height); list($width, $height)=getimagesize($file); if (isset($new_width) && !isset($new_height)) { $newwidth=$new_width; $newheight=$new_width/$width*$height; } else if (isset($new_height) && !isset($new_width)) { $newheight=$new_height; $newwidth=$new_height/$height*$width; } else if (isset($new_width) && isset($new_height)) { $newwidth=$new_width; $newheight=$new_height; } else { $newwidth=$width; $newheight=$height; } # Load image switch(exif_imagetype($file)) { case 1: $source=imagecreatefromgif($file); $content_type="image/gif"; break; case 2: $source=imagecreatefromjpeg($file); $content_type="image/jpeg"; break; case 3: $source=imagecreatefrompng($file); $content_type="image/png"; break; } # New image if(function_exists("imagecreatetruecolor") && $content_type!="image/png" && $content_type!="image/gif") $thumb=imagecreatetruecolor($newwidth, $newheight); else $thumb=imagecreate($newwidth, $newheight); # Resize image imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); # Output header("Content-type: ".$content_type); header("Last-Modified: ".date('r',filemtime($file))); if ($newwidth==$width && $newheight==$newheight) readfile($file); else { switch(exif_imagetype($file)) { case IMAGETYPE_JPEG: imagejpeg($thumb, null, 95); break; case IMAGETYPE_GIF: imagegif($thumb, null, 95); break; case IMAGETYPE_PNG: if (function_exists('imagesavealpha')) { imagealphablending($thumb, false); imagesavealpha($thumb, true); } imagepng($thumb, null, 95); break; } } die(); } |
||
Kajman_ Profil * |
#2 · Zasláno: 25. 6. 2008, 12:59:56
imagecopyresized nahradit imagecopyresampled
|
||
Actimel Profil * |
#3 · Zasláno: 25. 6. 2008, 13:03:54
Tisíceré díky! ;o)
|
||
srigi Profil |
#4 · Zasláno: 25. 6. 2008, 19:52:38
nj, pozor, ak mas niekde stranku kde budes generovat napr. 10 thumbailov, tak sa priprav na poriadnu zataz CPU servera. Thumbaily preto generovat uz pri uploade obrazkov.
|
||
Časová prodleva: 4 měsíce
|
|||
tone Profil * |
#5 · Zasláno: 29. 10. 2008, 15:09:44
můžu se zeptat jak bych výstup z této funkce mohl uložit do jpeg obrázku?
|
||
Alphard Profil |
#6 · Zasláno: 29. 10. 2008, 15:17:52
„jak bych výstup z této funkce mohl uložit do jpeg obrázku?“
uvedením cesty v druhém parametru funkce imagejpeg(), tedy místo null např. "obrazek.jpg" ještě dodám, že tato funkce se tváří, jako by uměla pracovat i s gif a png, ale imagegif() třetí parametr (kvalitu) nemá vůbec a u imagepng() nabývá jen hodnot 0 do 9 doopravte to |
||
Časová prodleva: 17 let
|
0