| | |
| Stránka: 1 z 1
| [ Príspevkov: 3 ] | |
Autor | Správa |
---|
Registrovaný: 01.10.07 Prihlásený: 03.02.14 Príspevky: 747 Témy: 152 Bydlisko: Bratislava |
Ak dobre viem, cez PHP sa daju resizovat subory. Dokaze vsak resizovat aj fotky na sirku/vysku? Dajme tomu ze chcem vsetky fotky na 800x600, avsak niektore su na sirku, niektore na vysku. Je jasne, ze tie na vysku by mali byt resiznute na 600x800 a nie naopak. Zvladne taketo nieco PHP? (uploadovane fotky by boli vzdy v pomere stran 4:3 alebo 3:4)
|
|
Registrovaný: 10.02.08 Prihlásený: 15.05.17 Príspevky: 2264 Témy: 48 Bydlisko: Nitra | Napísal Svolo: 11.02.2010 17:07 | |
|
Samozrejme...zistíš si rozmery a podľa toho ktorá strana je väčšia si určíš pomer zmenšenia vydelením na max. rozmer danej strany a potom už klasické funkcie pre prácu s obrázkami...
_________________ WYSIWYMGIYRRLAAGW: What You See Is What You Might Get If You’re Really Really Lucky And All Goes Well. |
|
Registrovaný: 07.03.06 Prihlásený: 23.01.11 Príspevky: 404 Témy: 2 Bydlisko: Prešov / Pr... | Napísal mylan: 11.02.2010 17:32 | |
|
Pomôžem rovno funkciou z MNews, ktorú som niekde našiel a upravil Kód: <?php function resize_img($img, $max_size, $newfilename) {
//Check if GD extension is loaded if (!extension_loaded('gd') && !extension_loaded('gd2')) { trigger_error('GD is not loaded', E_USER_WARNING); return false; }
//Get Image size info list($width_orig, $height_orig, $image_type) = getimagesize($img);
switch ($image_type) { case 1: $im = imagecreatefromgif($img); break; case 2: $im = imagecreatefromjpeg($img); break; case 3: $im = imagecreatefrompng($img); break; default: trigger_error('Unsupported filetype!', E_USER_WARNING); break; }
if ($width_orig > $height_orig) { $thumb_width = $max_size; $aspect_ratio = (float) $height_orig / $width_orig; $thumb_height = round($thumb_width * $aspect_ratio); } else { $thumb_height = $max_size; $aspect_ratio = (float) $width_orig / $height_orig; $thumb_width = round($thumb_height * $aspect_ratio); }
$newImg = imagecreatetruecolor($thumb_width, $thumb_height);
// Check if this image is PNG or GIF, then set if Transparent if(($image_type == 1) OR ($image_type==3)) { imagealphablending($newImg, false); imagesavealpha($newImg,true); $transparent = imagecolorallocatealpha($newImg, 255, 255, 255, 127); imagefilledrectangle($newImg, 0, 0, $thumb_width, $thumb_height, $transparent); } imagecopyresampled($newImg, $im, 0, 0, 0, 0, $thumb_width, $thumb_height, $width_orig, $height_orig);
//Generate the file, and rename it to $newfilename switch ($image_type) { case 1: imagegif($newImg, $newfilename); break; case 2: imagejpeg($newImg, $newfilename); break; case 3: imagepng($newImg, $newfilename); break; default: trigger_error('Failed resize image!', E_USER_WARNING); break; }
return $newfilename; } ?> Napríklad použitie pri wallpaperoch, kde originálne (veľké) obrázky sú v adresári /images/orig/ a vytvorené 800x600 obrázky ukladáš do /images/800x600/: Kód: <?php $source = './images/orig/wallpaper.jpg'; // súbor, z ktorého chceš zmenšeninu vytvoriť $target = './images/800x600/wallpaper.jpg'; cesta a názov súboru, kde to chceš uložiť nový zmenšený súbor
resize_img($source, '800', $target); ?>
|
|
| Stránka: 1 z 1
| [ Príspevkov: 3 ] | |
Podobné témy | Témy | Odpovede | Zobrazenia | Posledný príspevok |
---|
| resize obrazkov v PHP, ASP | 5 | 1003 | 25.09.2006 19:04 itsgoingd | | image resize v PHP, ASP | 2 | 510 | 13.10.2007 20:43 m@-nX | | Resize partiotion v Operačné systémy Unix a Linux | 2 | 425 | 05.12.2009 11:05 Ded'leg | | Fancybox - resize zoom v HTML, XHTML, XML, CSS | 5 | 373 | 07.02.2014 16:41 F3RY | | resize blob image v Databázy | 0 | 507 | 16.12.2009 13:07 pilná lama glama | | hromadne resize obrazkov v Ostatné | 6 | 908 | 07.08.2008 16:21 Gyrxiur | | resize ... failed open v PHP, ASP | 5 | 431 | 31.10.2007 15:56 etel | | Upload + konverzia + resize orázka v PHP, ASP | 2 | 400 | 21.12.2011 9:28 camo | | resize image problem s kvalitou v PHP, ASP | 8 | 544 | 17.12.2009 15:10 pilná lama glama | | PHP programátor - PHP, MySQL, jQuery,X)Html/CSS v Ponuka práce | 0 | 1310 | 02.05.2011 12:08 magicmedia | | Vytvorenie suboru php a vlozenie php scriptu v PHP, ASP | 4 | 1440 | 07.05.2010 14:02 DeiForm | | PHP nevie precitat .PHP v PHP, ASP | 8 | 831 | 18.03.2011 19:21 camo | | php ->mysql ->php Help.zoradit v PHP, ASP | 4 | 594 | 20.06.2009 12:44 KViki | | $pcforum->getForumActivity('PHP, ASP', 2012)/$pcforum->getForumActivity('PHP, ASP', 2022) - Warning: Division by zero v PHP, ASP | 4 | 2298 | 20.05.2022 13:51 JanoF | | PHP v PHP, ASP | 2 | 457 | 08.04.2016 20:44 5had0w | | PHP v PHP, ASP | 18 | 1181 | 01.01.2009 19:22 rooobertek |
| Nemôžete zakladať nové témy v tomto fóre Nemôžete odpovedať na témy v tomto fóre Nemôžete upravovať svoje príspevky v tomto fóre Nemôžete mazať svoje príspevky v tomto fóre
|
|