Autor | Zpráva | ||
---|---|---|---|
lenkali Profil * |
#1 · Zasláno: 16. 2. 2008, 10:35:46
Nevíte prosím, proč mi to deformuje obrazky?
takto načítám obrázek: $obrazekkamarada = $radek["id_kamarada"]; $obrazek = "kamaradi/".$obrazekkamarada."1.jpg"; if(file_exists($obrazek)){ printf("<a href=./np/".$obrazekkamarada."1.jpg target=_blank><img width=30 border=0 src=./kamaradi/resize.php?filename=".$obrazekkamarada."1.jpg></a></fon t></td> \n"); a to je soubor resize.php: <?php // File and new size $id = $_GET['filename']; // Content type header('Content-type: image/jpeg'); // Get new sizes // list($width, $height) = getimagesize($filename); list($width, $height) = getimagesize($id); $newwidth = 150; $newheight = 150; // Load $thumb = imagecreatetruecolor($newwidth, $newheight); // $source = imagecreatefromjpeg($filename); $source = imagecreatefromjpeg($id); // Resize imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); // Output imagejpeg($thumb); ?> |
||
Alphard Profil |
#2 · Zasláno: 16. 2. 2008, 10:40:56
$newwidth = 150;
$newheight = 150; vůbec neřešíš přepočet rozměrů vzhledem k poměru stran |
||
lenkali Profil * |
#3 · Zasláno: 16. 2. 2008, 10:43:18
Alpharde, jakože to nemám řešit nebo že to právě mám řešit a můžu se to někde dočíst,prosím?
|
||
Alphard Profil |
#4 · Zasláno: 16. 2. 2008, 10:46:11
http://php.vrana.cz/zmensovani-obrazku.php
mrkni na image_shrink_size() |
||
lenkali Profil * |
#5 · Zasláno: 16. 2. 2008, 11:06:05
zajimave, zkousim to, ale nejak to nefunguje, budu zkouset dal, presto, pokud byste vedeli uz naoko, co zpusobuje, ze se nic nezobrazuje a nefunguje, prosim o radu
funkce:image_shrink_size <?php // File and new size $id = $_GET['filename']; // Content type header('Content-type: image/jpeg'); // Get new sizes // list($width, $height) = getimagesize($filename); list($width, $height) = image_shrink_size(getimagesize($id), 150, 150); //list($width, $height) = getimagesize($id); $newwidth = 150; $newheight = 150; // Load $thumb = imagecreatetruecolor($newwidth, $newheight); // $source = imagecreatefromjpeg($filename); $source = imagecreatefromjpeg($id); // Resize imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); // Output imagejpeg($thumb); ?> |
||
Alphard Profil |
#6 · Zasláno: 16. 2. 2008, 11:12:48
image_shrink_size() je uživatelská funkce, takže musíš nakopírovat její kód, navíc první parametr je jméno souboru
zkus to taklhe: <?php function image_shrink_size($file_in, $max_x = 0, $max_y = 0) { list($width, $height) = getimagesize($file_in); if (!$width || !$height) { return array(0, 0); } if ($max_x && $width > $max_x) { $height = round($height * $max_x / $width); $width = $max_x; } if ($max_y && $height > $max_y) { $width = round($width * $max_y / $height); $height = $max_y; } return array($width, $height); } $id = $_GET['filename']; // Content type header('Content-type: image/jpeg'); // Get new sizes list($newwidth, $newheight) = image_shrink_size($id, 150, 150); // Load $thumb = imagecreatetruecolor($newwidth, $newheight); $source = imagecreatefromjpeg($id); // Resize imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); // Output imagejpeg($thumb); ?> |
||
lenkali Profil * |
#7 · Zasláno: 16. 2. 2008, 11:22:27
$id = $_GET['filename'];
header('Content-type: image/jpeg'); list($newwidth, $newheight) = image_shrink_size(getimagesize($id), 150, 150); může být chyba prosím v těchto třech řádcích, pořád se mi nezobrazují obrázky? Asi se špatně odvolávám na daný soubor, nevím, jak to zapsat do tohoto: list($newwidth, $newheight) = image_shrink_size(getimagesize($id), 150, 150); když před tím, zjišťuju soubor v tomto: $id = $_GET['filename']; |
||
lenkali Profil * |
#8 · Zasláno: 16. 2. 2008, 11:23:01
$id = $_GET['filename'];
header('Content-type: image/jpeg'); list($newwidth, $newheight) = image_shrink_size(getimagesize($id), 150, 150); může být chyba prosím v těchto třech řádcích, pořád se mi nezobrazují obrázky? Asi se špatně odvolávám na daný soubor, nevím, jak to zapsat do tohoto: list($newwidth, $newheight) = image_shrink_size(getimagesize($id), 150, 150); když před tím, zjišťuju soubor v tomto: $id = $_GET['filename']; |
||
Alphard Profil |
#9 · Zasláno: 16. 2. 2008, 11:26:12
vždyť jsem to psal
list($newwidth, $newheight) = image_shrink_size($id, 150, 150); |
||
lenkali Profil * |
#10 · Zasláno: 16. 2. 2008, 11:31:01
nějak to nefunguje, pořád to neotevře obrázek, je tam křížek....
proto se s tím snažím něco dělat, určitě zase něco dělám špatně |
||
lenkali Profil * |
#11 · Zasláno: 16. 2. 2008, 11:34:26
function image_shrink_size($file_in, $max_x = 0, $max_y = 0)
Nemám u toho $file_in nějak zadat cestu k tomu obrázku? |
||
lenkali Profil * |
#12 · Zasláno: 16. 2. 2008, 12:12:57
Nevíte prosím, co s tím můžu ještě udělat?
takto načítám obrázek: $obrazekkamarada = $radek["id_kamarada"]; $obrazek = "kamaradi/".$obrazekkamarada."1.jpg"; if(file_exists($obrazek)){ printf("<a href=./np/".$obrazekkamarada."1.jpg target=_blank><img width=30 border=0 src=./kamaradi/resize.php?filename=".$obrazekkamarada."1.jpg></a></fon t></td> \n"); a toto je nynější resize.php <?php function image_shrink_size($file_in, $max_x = 0, $max_y = 0) { list($width, $height) = getimagesize($file_in); if (!$width || !$height) { return array(0, 0); } if ($max_x && $width > $max_x) { $height = round($height * $max_x / $width); $width = $max_x; } if ($max_y && $height > $max_y) { $width = round($width * $max_y / $height); $height = $max_y; } return array($width, $height); } $id = $_GET['filename']; // Content type header('Content-type: image/jpeg'); // Get new sizes list($newwidth, $newheight) = image_shrink_size($id, 150, 150); // Load $thumb = imagecreatetruecolor($newwidth, $newheight); $source = imagecreatefromjpeg($id); // Resize imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); // Output imagejpeg($thumb); ?> |
||
Alphard Profil |
#13 · Zasláno: 16. 2. 2008, 12:14:33 · Upravil/a: Alphard
já můžu pouze hádat, neznám tvou adresářovou strukturu, nevím, čeho chceš přesně dosáhnout a tak dále
asi lepší funkce bude ta na stránce http://php.vrana.cz/formaty-obrazku.php je to kompletní funkce, která spočítá velikosti stran, určí formát a nakonec obrázek zmenší, jediná věc, která se ti nehodí je ukládání obrázků, takže ji trochu upravím: následující kód zkopíruj a neměň function image_shrink($file_in, $max_x, $max_y = 0) { $imagesize = getimagesize($file_in); if ((!$max_x && !$max_y) || !$imagesize[0] || !$imagesize[1]) { return false; } switch ($imagesize[2]) { case 1: $img = imagecreatefromgif($file_in); break; case 2: $img = imagecreatefromjpeg($file_in); break; case 3: $img = imagecreatefrompng($file_in); break; default: return false; } if (!$img) { return false; } if ($max_x) { $width = $max_x; $height = round($imagesize[1] * $width / $imagesize[0]); } if ($max_y && (!$max_x || $height > $max_y)) { $height = $max_y; $width = round($imagesize[0] * $height / $imagesize[1]); } $img2 = imagecreatetruecolor($width, $height); imagecopyresampled($img2, $img, 0, 0, 0, 0, $width, $height, $imagesize[0], $imagesize[1]); if ($imagesize[2] == 2) { return imagejpeg($img2); } elseif ($imagesize[2] == 1 && function_exists("imagegif")) { imagetruecolortopalette($img2, false, 256); return imagegif($img2); } else { return imagepng($img2); } } pod to vlož kód $cesta = "cesta k obrázku"; image_shrink($cesta, 150, 150); jediná věc, kterou j etřeba upravit je proměnná $cesta, zadej do ní cestu k obrázku |
||
lenkali Profil * |
#14 · Zasláno: 16. 2. 2008, 12:21:16
JEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
FUNGUJEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE ALPHARDEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE DEKUJIIIIIIIIIIIIIIIIII MOOOOOOOOOOOOOOOCCCCCCCCCCCCCCCCCCCCCCCCCCCCC :o):o):o):o):o):o):o):o):o):o):o):o):o):o):o):o):o):o):o)v :o):o):o) to je úžasné a obrázky nejsou zdeformované, děkujiiiii |
||
Časová prodleva: 16 let
|
0