Autor Zpráva
študent
Profil *
Skúšal som rôzne scripty na zmenšenie obrázkov aj z fóra aj čo som našiel v google. Buď boli zložité, alebo som im neporozumel a ani jeden som nevedel spojazdniť. Vie mi niekto povedať, kde by som našiel čo najjednoduchší návod alebo zrozumiteľný script na zmenšenie obrázku, najlepšie aj s uploadom na server. Som len začiatočník tak sa vopred ospravedlňujem :-).
creck
Profil
http://diskuse.jakpsatweb.cz/index.php?action=vthread&forum=9&topic=25 183
študent
Profil *
Ahoj creck. Práve tento script som skúšal a nefungoval mi. Vieš mi povedať ako si ho mám prispôsobiť okrem zmeny $path? Dík
creck
Profil
no, to co jsi zkousel neni script, ale pouze funkce ...

takze kdyz odesles formular s obrazkem, tak:


tady budou ty funkce ...

if(isset($_POST['send'])) {
if(!img_copy($_FILES['foto']['tmp_name'], 'tady bych dal ID uzivatele') {
echo 'obrazek se nepodarilo zkopirovat';
}
else {
img_resized('tady bude to ID uzivatele', 'velikost_obrazku');
}
}

<form method="post" action="" enctype="multipart/form-data">
<input type="file" name="foto">
<input type="submit" value="odeslat">
<input type="hidden" name="send">
</form>


prectete si jeste tady tohle forum, dneska se to resilo.
http://diskuse.jakpsatweb.cz/index.php?action=vthread&forum=9&topic=25 823
creck
Profil
JE TO OSETRENO POUZE PRO UPLOAD SOUBORU TYPU *.JPG
študent
Profil *
Ahoj creck. Ako skúšam tak skúšam tak to nejde. Mám tento kód:

/*

*

* funkce pro praci s obrazky

*

*/



$path = './foto/';



// zkopirujeme obrazek do slozky

function img_copy($img, $name) {



global $path;



if(!move_uploaded_file($img, $path . 'ORIG_' . $name . '.jpg')) {

return false;

}

else {

return true;

}

}





// upravi velikost, prida text

// $size = velky NEBO hlavni NEBO maly

function img_resized($img, $size) {



global $path;



// priradime priponu

$img .= '.jpg';



// zjistime rozmery obrazku

$imgSize = getimagesize($path . 'ORIG_' . $img);



// zjistime sirku a vysku

$width_img = $imgSize[0];

$height_img = $imgSize[1];



// maximalni rozmery obrazku

switch($size) {



case 'velky':

$width_max = 500;

$height_max = 625;

$prefix = 'velky_';

break;



case 'hlavni':

$width_max = 250;

$height_max = 313;

$prefix = 'hlavni_';

break;



case 'maly':

$width_max = 100;

$height_max = 125;

$prefix = 'maly_';

break;

}



// jaky je pomer stran

$pomer_width = $width_max / ($width_img / 100);

$pomer_height = $height_max / ($height_img / 100);



// nastavime maximalni rozmerz

if($width_img<$width_max) {

$width = $width_img;

$height = $height_img;

if($height_img>$height_max) {

$width = round($width_img / 100 * $pomer_height);

$height = round($height_img / 100 * $pomer_height);

}

}



if($width_img>$width_max) {

$width = round($width_img / 100 * $pomer_width);

$height = round($height_img / 100 * $pomer_width);

if($height>$height_max) {

$width = round($width_img / 100 * $pomer_height);

$height = round($height_img / 100 * $pomer_height);

}

}



// vytvorime novy obrazek

$img_in = imagecreatefromjpeg($path . 'ORIG_' . $img);



// barevny obrazek

$img_out = imagecreatetruecolor($width, $height);



/*



VYPISE TEXT V OBRAZKU



$bila = imagecolorallocate($img_in, 255, 255, 255);

imagestring($img_in, 1, 0, 0, 'test textu v obrazku ', $bila);

*/



// zkopirujeme novou velikost

imagecopyresampled($img_out, $img_in, 0, 0, 0, 0, $width, $height, $width_img,

$height_img);



// ulozime

// tady si muzes hrat stema adresarama, jak potrebujes ...

imagejpeg($img_out, $path . $prefix . $img);

}


if(isset($_POST['send'])) {

if(!img_copy($_FILES['foto']['tmp_name'])) {

echo 'obrazek se nepodarilo zkopirovat';

}

else {

img_resized('maly');

}

}

?>

<form method="post" action="" enctype="multipart/form-data">

<input type="file" name="foto">

<input type="submit" value="odeslat">

<input type="hidden" name="send">

</form>
Toto téma je uzamčeno. Odpověď nelze zaslat.

0