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 |
#2 · Zasláno: 7. 5. 2006, 22:39:18
|
||
študent Profil * |
#3 · Zasláno: 7. 5. 2006, 22:47:43
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 |
#4 · Zasláno: 7. 5. 2006, 22:54:44 · Upravil/a: creck
no, to co jsi zkousel neni script, ale pouze funkce ...
takze kdyz odesles formular s obrazkem, tak: 1
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 |
#5 · Zasláno: 7. 5. 2006, 22:56:13 · Upravil/a: creck
JE TO OSETRENO POUZE PRO UPLOAD SOUBORU TYPU *.JPG
|
||
študent Profil * |
#6 · Zasláno: 8. 5. 2006, 10:40:48
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> |
||
Časová prodleva: 19 let
|
Toto téma je uzamčeno. Odpověď nelze zaslat.
0