View previous topic :: View next topic |
Author |
Message |
raytech
Joined: 17 Mar 2004 Posts: 396 Location: Zagreb
|
Posted: 19.06.2004 20:46 Post subject: Resize slika?????? |
|
|
HELP. Ima skriptu za upload podatak koja ima dva dijela
1.upload obrazac
Quote: | <form action="upload.php" method="post" ENCTYPE="multipart/form-data">
<!-- the 'name' field on the input below is very important -->
Izaberite sliku:
<input name="jpgimage" type="file" class="basic" size="30">
<!-- set the max file size -->
<input type="hidden" name="MAX_FILE_SIZE" value="500000">
<!-- submit button -->
<input type="submit" class="basic" value="upload">
<!-- end the form -->
</form> |
2. upload
Quote: | <?
//the absolute location of where you want to upload it
//the directory must be chmoded 777
//jpgimage is the name from the top
copy($jpgimage,"assets/slike/$jpgimage_name");
unlink($jpgimage);
?> |
Sad kaj bi ja trebao napraviti da mi taj obrazac smanjuje slike na 105 px widtha,
height nije bitnan
Znam da trebam napistai neki function, ali MUUUUUUUUUUUU. My kung fu is weak in the code way. |
|
|
Back to top |
|
|
smasher
Joined: 10 Jan 2004 Posts: 229 Location: Zaprešić
|
Posted: 19.06.2004 21:06 Post subject: |
|
|
hah, ak oš prikazivat, tj. smanjivat sliku, onda je to lako, al ak oš baš "fizički" smanjit sliju, hmhm, nemam pojma za to, al mislim da je to malo kompliciraniji posao od samo naredbe za to...
nisam baš siguran za što će ti to točno, pa nemrem ni odgovorit baš dobro
a i moraš uzet u obzir da ja tek učim... heh. al rado pomognem ak znam
pa onda reci kaj hoćeš... thumbse radit ili kaj? |
_________________ http://3DHR.net - Srce hrvatskih 3d artista
http://www.Rhino3DHelp.com |
|
Back to top |
|
|
silence
Joined: 24 Apr 2004 Posts: 890 Location: .....ni na nebu, ni na zemlji.....
|
Posted: 19.06.2004 21:15 Post subject: |
|
|
hm. ja baš i nisam ljubitelj skripti koje zahtjevaju chmod 777.
možda da potražiš nekaj drugo? |
_________________ This End-User License is an agreement between Microsoft Corporation (hereafter referred to as "Microsoft") and you, the end-user (hereafter referred to as "our bitch"). |
|
Back to top |
|
|
maxy
Joined: 07 Sep 2003 Posts: 894 Location: Zagreb
|
Posted: 19.06.2004 21:50 Post subject: |
|
|
silence wrote: | hm. ja baš i nisam ljubitelj skripti koje zahtjevaju chmod 777.
možda da potražiš nekaj drugo? |
ja sam probo nekidan aplodat u dir koji je imo 775 chmod i nije islo
evo ti komad koda za resizanje, mora radit na svakom serveru sa GD libom:
Code: | function Resize($sourcefile, $destfile, $fw, $fh, $jpegquality = 60)
{
list($ow, $oh, $from_type) = getimagesize($sourcefile);
switch($from_type)
{
case 1: // GIF
$srcImage = imageCreateFromGif($sourcefile);
break;
case 2: // JPG
$srcImage = imageCreateFromJpeg($sourcefile);
break;
case 3: // PNG
$srcImage = imageCreateFromPng($sourcefile);
break;
}
$tempw = $fw;
$temph = number_format((($oh*$fw)/$ow), 0);
if($temph < $fh)
{
$tempw = number_format((($ow*$fh)/$oh), 0);
$temph = $fh;
}
$tempImage = imageCreateTrueColor($tempw, $temph);
//imageAntiAlias($tempImage, true);
imagecopyresampled($tempImage, $srcImage, 0, 0, 0, 0, $tempw, $temph, $ow, $oh);
// Calculate offsets
if($temph > $fh)
{
$offsety = number_format(($temph/2)-($fh/2), 0);
$offsetx = 0;
}
else
{
$offsety = 0;
$offsetx = number_format(($tempw/2)-($fw/2), 0);
}
$destImage = imageCreateTrueColor($fw, $fh);
imagecopyresampled($destImage, $tempImage, 0, 0, $offsetx, $offsety, $fw, $fh, $fw, $fh);
imageJpeg($destImage, $destfile, $jpegquality);
} |
kak radis sa tim:
recimo aplodas neku sliku i oces sad da ti bude dimenzija 60x60 i da stoji u direktoriju /assets/slike
Resize($_FILES['file']['tmp_name'], '/assets/slike/'.$_FILES['file']['name'], 60, 60);
i bok.
ak ti nest nije jasno, vici. |
|
|
Back to top |
|
|
silence
Joined: 24 Apr 2004 Posts: 890 Location: .....ni na nebu, ni na zemlji.....
|
Posted: 19.06.2004 22:09 Post subject: |
|
|
maxy wrote: | silence wrote: | hm. ja baš i nisam ljubitelj skripti koje zahtjevaju chmod 777.
možda da potražiš nekaj drugo? |
ja sam probo nekidan aplodat u dir koji je imo 775 chmod i nije islo
. |
sjećaš se onog mog koda za upload, di sam iz tempa prebacivao u konačni direktorij s FTPom?...kaj misliš zakaj sam to pisao
možda nije najelegantnije rješenje, ali onda ti direktorij ne mora biti 777 |
_________________ This End-User License is an agreement between Microsoft Corporation (hereafter referred to as "Microsoft") and you, the end-user (hereafter referred to as "our bitch"). |
|
Back to top |
|
|
maxy
Joined: 07 Sep 2003 Posts: 894 Location: Zagreb
|
Posted: 19.06.2004 22:24 Post subject: |
|
|
a gle, ak si tolki paranoik onda napravi aplod skriptu koja chmoda dir na 777 pa mu poslje uploada stavi chmod 775 ili koji vec i mirna bosna |
|
|
Back to top |
|
|
silence
Joined: 24 Apr 2004 Posts: 890 Location: .....ni na nebu, ni na zemlji.....
|
Posted: 19.06.2004 22:35 Post subject: |
|
|
maxy wrote: | a gle, ak si tolki paranoik onda napravi aplod skriptu koja chmoda dir na 777 pa mu poslje uploada stavi chmod 775 ili koji vec i mirna bosna |
ma LOL. nisam baš tolki paranoik.
ustvari između paranoje i ljenosti uvijek biram ljenost, tak da nema šanse da idem sad novu skriptu pisat....ono kaj imam radi i radi zadovoljavajuće....još samo da puknem resize unutra i to bi bilo to (ali sam ljen, pa će resize pričekat)...
|
_________________ This End-User License is an agreement between Microsoft Corporation (hereafter referred to as "Microsoft") and you, the end-user (hereafter referred to as "our bitch"). |
|
Back to top |
|
|
raytech
Joined: 17 Mar 2004 Posts: 396 Location: Zagreb
|
Posted: 19.06.2004 23:02 Post subject: Vićem |
|
|
AAAAAAAAAAAAAAAAAAAA
@ maxy: O.k ajmo koda razgovarš s policajcem(inteligence wise)
znaći moram imati dva file. jedan function.php i drugi obrazac php.
Jel se to može inegrati u onaj kod gore. Stvarno sam tek početnik u php.
Što sad ide u ono malo više što si napisao to je funkcija, a što mi treba za obrazac. Mislim što trebam integrati u ono formu da se to poveže, i dali mi treba još onaj upload.php????
E da želim da se slikca ima constrain proprtions, tj samo mi treba smanjit image 105 px širine, a height je nedefiniran.
Sorry glup sam znam ali jebiga, volio bih debelo ući u kod ali nikao da nađem vremena.
@samsher: Evo vidi što radim http://www.kunkera.hr/hvs username: HVS, password:hvs |
|
|
Back to top |
|
|
t3r0
Joined: 08 Jun 2004 Posts: 107
|
Posted: 20.06.2004 01:31 Post subject: Re: Vićem |
|
|
raytech wrote: | AAAAAAAAAAAAAAAAAAAA
@ maxy: O.k ajmo koda razgovarš s policajcem(inteligence wise)
znaći moram imati dva file. jedan function.php i drugi obrazac php.
Jel se to može inegrati u onaj kod gore. Stvarno sam tek početnik u php. |
ne moras imati 2 fajla, samo dodas ovu funkciju sto je maxy napisao u taj fajl koji prima podatke (sliku).
I onda pozoves funkciju kao sto je maxy napisao:
Resize($_FILES['file']['tmp_name'], '/assets/slike/'.$_FILES['file']['name'], 60, 60);
raytech wrote: | Što sad ide u ono malo više što si napisao to je funkcija, a što mi treba za obrazac. Mislim što trebam integrati u ono formu da se to poveže, i dali mi treba još onaj upload.php???? |
u obrazac ne moras nista dodati jer ce nakon uploada funkcija napraviti thumbnail i spremiti ga tamo gdje joj kazes. |
|
|
Back to top |
|
|
silence
Joined: 24 Apr 2004 Posts: 890 Location: .....ni na nebu, ni na zemlji.....
|
Posted: 20.06.2004 08:34 Post subject: Re: Vićem |
|
|
raytech wrote: |
E da želim da se slikca ima constrain proprtions, tj samo mi treba smanjit image 105 px širine, a height je nedefiniran.
|
kolko sam skužio recimo imaš dvije slike...jednu 105x140 i drugu 100x100 i na kraju onje trebaju stati u prostor 60x60?
nakon uploada možeš dobiti veličinu slike pomoću
getimagesize() funkcije koja vraća array gdje je [0] širina, a [1] visina.
zatim bi trebo stavit tri uvijeta širina>visina, širina == visina, širina < visina i prema njima izračunat nove dimenzije.
tek sam se probudio, pa ak sam nekaj fulo nek me maxy ispravi |
_________________ This End-User License is an agreement between Microsoft Corporation (hereafter referred to as "Microsoft") and you, the end-user (hereafter referred to as "our bitch"). |
|
Back to top |
|
|
maxy
Joined: 07 Sep 2003 Posts: 894 Location: Zagreb
|
Posted: 20.06.2004 09:37 Post subject: |
|
|
// upload php
function Resize($sourcefile, $destfile, $fw, $fh, $jpegquality = 60)
{
list($ow, $oh, $from_type) = getimagesize($sourcefile);
switch($from_type)
{
case 1: // GIF
$srcImage = imageCreateFromGif($sourcefile);
break;
case 2: // JPG
$srcImage = imageCreateFromJpeg($sourcefile);
break;
case 3: // PNG
$srcImage = imageCreateFromPng($sourcefile);
break;
}
$tempw = $fw;
$temph = number_format((($oh*$fw)/$ow), 0);
if($temph < $fh)
{
$tempw = number_format((($ow*$fh)/$oh), 0);
$temph = $fh;
}
$tempImage = imageCreateTrueColor($tempw, $temph);
//imageAntiAlias($tempImage, true);
imagecopyresampled($tempImage, $srcImage, 0, 0, 0, 0, $tempw, $temph, $ow, $oh);
// Calculate offsets
if($temph > $fh)
{
$offsety = number_format(($temph/2)-($fh/2), 0);
$offsetx = 0;
}
else
{
$offsety = 0;
$offsetx = number_format(($tempw/2)-($fw/2), 0);
}
$destImage = imageCreateTrueColor($fw, $fh);
imagecopyresampled($destImage, $tempImage, 0, 0, $offsetx, $offsety, $fw, $fh, $fw, $fh);
imageJpeg($destImage, $destfile, $jpegquality);
}
list($height, $width) = @getimagesize($_FILES['jpgimage']['tmp_name'];
// idemo sad smanjit sliku na 105 pix
if($width > 105)
{
$ratio = round($width/105);
$width = 105;
$height = floor($height/$ratio);
}
// gdje oces spremit sliku?
$destination_directory = '/assets/slike/'.$_FILES['jpgimage']['name'];
// pozovi funkciju da sejvas fajlove
Resize($_FILES['jpgimage']['tmp_name'], $destination_directory, $width, $height); |
|
|
Back to top |
|
|
raytech
Joined: 17 Mar 2004 Posts: 396 Location: Zagreb
|
Posted: 20.06.2004 10:29 Post subject: Kralj SI |
|
|
@MAXY.
Respect
Javalja mi grešku u ovom redu, što znači da mi GD ni je uključen I THiNK.
Kak se uključuje GD????????
list($height, $width) = @getimagesize($_FILES['jpgimage']['tmp_name']; |
|
|
Back to top |
|
|
maxy
Joined: 07 Sep 2003 Posts: 894 Location: Zagreb
|
Posted: 20.06.2004 10:59 Post subject: |
|
|
napisi koju ti gresku tocno prijavi... |
|
|
Back to top |
|
|
maxy
Joined: 07 Sep 2003 Posts: 894 Location: Zagreb
|
Posted: 20.06.2004 11:02 Post subject: |
|
|
eto sto se dogodi kad ides samo kopipejstat
imam sytax error pa ti evo ispravljen komad koda:
list($height, $width) = @getimagesize($_FILES['jpgimage']['tmp_name']); |
|
|
Back to top |
|
|
raytech
Joined: 17 Mar 2004 Posts: 396 Location: Zagreb
|
Posted: 20.06.2004 11:43 Post subject: Sad mi je već neugodno |
|
|
Sad mi je već neugodno
Za ovaj red(12)
Quote: |
$srcImage = imageCreateFromJpeg($sourcefile);
break; |
veli ovo
Quote: | Fatal error: Call to undefined function: imagecreatefromjpeg() in c:\apache\htdocs\hvs\upload.php on line 12
|
E da, ja još uvjek pozivam taj upload php, iz obrazca.php, a ak bi napravio formu u upload.php kak onda pozovem funkciju "resize".
Da ovaj dio prebacim u upload.php
Quote: | <form action="upload.php" method="post" ENCTYPE="multipart/form-data">
<!-- the 'name' field on the input below is very important -->
Izaberite sliku:
<input name="jpgimage" type="file" class="basic"
size="30">
<!-- set the max file size -->
<input type="hidden" name="MAX_FILE_SIZE" value="500000">
<!-- submit button -->
<input type="submit" class="basic" value="upload">
<!-- end the form -->
</form></td> |
jel moram promjenit ovo Quote: | form action="upload.php" | u nešto? |
|
|
Back to top |
|
|
maxy
Joined: 07 Sep 2003 Posts: 894 Location: Zagreb
|
Posted: 20.06.2004 13:23 Post subject: |
|
|
za ovu gresku koju ti javlja - to znaci da nemas GD library instaliran kod sebe na kompu. stoga trebas to testirati na nekom serveru koji to ima instalirano.
ovu funkciju trebas strpati negdje u file koji obradjuje podatke iz formulara. |
|
|
Back to top |
|
|
Phiber
Joined: 18 Apr 2004 Posts: 319 Location: Čakovec, Kroejša
|
|
Back to top |
|
|
_butch
Joined: 10 Sep 2003 Posts: 870 Location: Maichno, Krlovc
|
Posted: 20.06.2004 14:16 Post subject: |
|
|
posto je istekao patent na gif, php 4.3.7 ga sada podrzava, pa se sve moze raditi |
_________________ FRENCH GUARD: No chance, English bed-wetting types.
I burst my pimples at you and call your door-opening request a silly thing, you tiny-brained wipers of other people's bottoms! Flikrac |
|
Back to top |
|
|
raytech
Joined: 17 Mar 2004 Posts: 396 Location: Zagreb
|
Posted: 20.06.2004 15:02 Post subject: DA |
|
|
ali meni ne radi jer nemam pojma gdje treba ugurat onu funkciju.
Good damn PHP. |
|
|
Back to top |
|
|
silence
Joined: 24 Apr 2004 Posts: 890 Location: .....ni na nebu, ni na zemlji.....
|
Posted: 20.06.2004 15:06 Post subject: |
|
|
funkciju za mjenjanje veličine?
pa nakon što se datoteka uploada
dakle, negdje u upload.php ako se ne varam..... |
_________________ This End-User License is an agreement between Microsoft Corporation (hereafter referred to as "Microsoft") and you, the end-user (hereafter referred to as "our bitch"). |
|
Back to top |
|
|
maxy
Joined: 07 Sep 2003 Posts: 894 Location: Zagreb
|
Posted: 20.06.2004 15:28 Post subject: Re: DA |
|
|
raytech wrote: | ali meni ne radi jer nemam pojma gdje treba ugurat onu funkciju.
Good damn PHP. |
pa u jebeni file koji ti je naveden kao target formulara
isuse, zivce ces mi popit! |
|
|
Back to top |
|
|
raytech
Joined: 17 Mar 2004 Posts: 396 Location: Zagreb
|
Posted: 20.06.2004 15:31 Post subject: |
|
|
Quote: | isuse, zivce ces mi popit! |
sorry dude,
Ali radi sad, jejejejejejejejejejejejejejejeje. Sorry moj mozak radi tako da komplicira di netreba. |
|
|
Back to top |
|
|
maxy
Joined: 07 Sep 2003 Posts: 894 Location: Zagreb
|
Posted: 20.06.2004 19:53 Post subject: |
|
|
i bolje ti je da radi |
|
|
Back to top |
|
|
Tomica
Joined: 16 May 2004 Posts: 39 Location: Novi Marof, CRO
|
Posted: 27.06.2004 00:59 Post subject: |
|
|
.. a da sad ja malo zakompliciram! Dal netko zna kak sve to napraviti bez GD-a? |
|
|
Back to top |
|
|
t3r0
Joined: 08 Jun 2004 Posts: 107
|
|
Back to top |
|
|
|