Autor Zpráva
lenkali
Profil *
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
$newwidth = 150;
$newheight = 150;


vůbec neřešíš přepočet rozměrů vzhledem k poměru stran
lenkali
Profil *
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
http://php.vrana.cz/zmensovani-obrazku.php
mrkni na image_shrink_size()
lenkali
Profil *
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
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 *
$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 *
$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
vždyť jsem to psal
list($newwidth, $newheight) = image_shrink_size($id, 150, 150);
lenkali
Profil *
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 *
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 *
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
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 *
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

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0