Autor Zpráva
Lamca
Profil *
Zdravím mam několik file po uploadu uložim fotky na server ale pak potřebuju aby se ke všem vytvořili nahledy, mám to takhle:


<?
function resize_then_crop( $filein,$fileout,
$imagethumbsize_w,$imagethumbsize_h,$red,$green,$blue)
{

// Get new dimensions
list($width, $height) = getimagesize($filein);
$new_width = $width * $percent;
$new_height = $height * $percent;

if(preg_match("/.jpg/i", "$filein"))
{
$format = 'image/jpeg';
}
if (preg_match("/.gif/i", "$filein"))
{
$format = 'image/gif';
}
if(preg_match("/.png/i", "$filein"))
{
$format = 'image/png';
}

switch($format)
{
case 'image/jpeg':
$image = imagecreatefromjpeg($filein);
break;
case 'image/gif';
$image = imagecreatefromgif($filein);
break;
case 'image/png':
$image = imagecreatefrompng($filein);
break;
}

$width = $imagethumbsize_w ;
$height = $imagethumbsize_h ;
list($width_orig, $height_orig) = getimagesize($filein);

if ($width_orig < $height_orig) {
$height = ($imagethumbsize_w / $width_orig) * $height_orig;
} else {
$width = ($imagethumbsize_h / $height_orig) * $width_orig;
}

if ($width < $imagethumbsize_w)
//if the width is smaller than supplied thumbnail size
{
$width = $imagethumbsize_w;
$height = ($imagethumbsize_w/ $width_orig) * $height_orig;;
}

if ($height < $imagethumbsize_h)
//if the height is smaller than supplied thumbnail size
{
$height = $imagethumbsize_h;
$width = ($imagethumbsize_h / $height_orig) * $width_orig;
}

$thumb = imagecreatetruecolor($width , $height);
$bgcolor = imagecolorallocate($thumb, $red, $green, $blue);
ImageFilledRectangle($thumb, 0, 0, $width, $height, $bgcolor);
imagealphablending($thumb, true);

imagecopyresampled($thumb, $image, 0, 0, 0, 0,
$width, $height, $width_orig, $height_orig);
$thumb2 = imagecreatetruecolor($imagethumbsize_w , $imagethumbsize_h);
// true color for best quality
$bgcolor = imagecolorallocate($thumb2, $red, $green, $blue);
ImageFilledRectangle($thumb2, 0, 0,
$imagethumbsize_w , $imagethumbsize_h , $white);
imagealphablending($thumb2, true);

$w1 =($width/2) - ($imagethumbsize_w/2);
$h1 = ($height/2) - ($imagethumbsize_h/2);

imagecopyresampled($thumb2, $thumb, 0,0, $w1, $h1,
$imagethumbsize_w , $imagethumbsize_h ,$imagethumbsize_w, $imagethumbsize_h);

// Output
header('Content-type: image/gif');
imagegif($thumb); //output to browser first image when testing

if ($fileout !="")imagegif($thumb2, $fileout); //write to file
header('Content-type: image/gif');
imagegif($thumb2); //output to browser
}


$filein = 'upload/'.$_FILES['upload'][$i]['name'].''; // File in
$fileout = 'upload/maly_'.$_FILES['upload'][$i]['name'].'.jpg'; // Fileout - optional

$imagethumbsize_w = 200; // thumbnail size (area cropped in middle of image)
$imagethumbsize_h = 200; // thumbnail size (area cropped in middle of image)
resize_then_crop( $filein,$fileout,$imagethumbsize_w,
$imagethumbsize_h,/*rgb*/"255","255","255");
?>


ale to nejde. pokud udělam jeden FILE tak to funguje bez porblému ale jak jich je vic tak to nefunguje .. nevíte jak to napsat?? predem dekuju moc za rady..
nightfish
Profil
// Output
header('Content-type: image/gif');
imagegif($thumb); //output to browser first image when testing

if ($fileout !="")imagegif($thumb2, $fileout); //write to file
header('Content-type: image/gif');
imagegif($thumb2); //output to browser

tohle ten soubor vypíše celkem 3x - 2x do stránky (s dvojitým posláním hlaviček) a jednou do souboru...
celé bych to smazat a dal tam jenom
if (!empty($fileout)) imagegif($thunb2, $fileout);

PS: otázkou zůstává, proč používáš imagegif, když to ukládáš do souboru s příponou .jpg
Lamca
Profil *
ted uz ukladam do gif :) a nefacha to.. kdyz to uploadnu vsechny obrazky se tam hodi ale nezmensi jen se ve slozce upload vytvori soubor "maly_"
Lamca
Profil *
cim by to mohlo byt vi nekdo??
Toto téma je uzamčeno. Odpověď nelze zaslat.