JPG Upload and Resize [rezolvat]

Secţiune dedicată începatorilor.

Moderatori: Moderatori, Start Moderator

ashantyk
PHPRomania Supporter
Mesaje: 22
Membru din: Sâm Ian 19, 2008 10:49 pm
Localitate: Vaslui
Contact:

JPG Upload and Resize [rezolvat]

Mesajde ashantyk » Mar Ian 29, 2008 11:55 pm

scriptul asta ar trebui sa urce o imagine jpg pe server si s-o scaleze la o rezolutie mai mica........faza e ca-mi da eraore la decodare.... help..


<?php

if ($_FILES['avatar']['name']!=''){

if ($_POST[id_type]=='yahoo.com') { $fprefix='y_'; }
elseif ($_POST[id_type]=='hotmail.com') { $fprefix='hm_'; }
elseif ($_POST[id_type]=='gmail.com') { $fprefix='g_'; }
elseif ($_POST[id_type]=='aim.com') { $fprefix='aim_'; }
elseif ($_POST[id_type]=='skype') { $fprefix='sk_'; }


//ext
$ext = ".jpg";
//end ext


$fileFname = $fprefix . $_POST['id'] . $ext;
copy ($_FILES['avatar']['tmp_name'], "avatare/"$fileFname) or die ("Nu s-a putut copia avatarul pe server!");

$data = fread(fopen($_FILES['avatar']['tmp_name'], "rb"), filesize($_FILES['avatar']['tmp_name']));
$src_image = imagecreatefromstring($data);
$width = imagesx($src_image);
$height = imagesy($src_image);

if ($height > 128 OR $width > 128){
if ($width < $height) {
$av_ratio1 = $width / $height;
$av_height = 128;
$av_width = round(128 * $av_ratio1);}
else {$av_ratio2 = $height / $width;
$av_width = 128;
$av_height = round(128 * $av_ratio2);}}
elseif ($height == 128 AND $width == 128)
{$av_height = 128;
$av_width = 128;}
else {$av_height=$height;
$av_width=$width;}


//resizing

$tmpimg = tempnam("/avatare", "MKUP");
system("djpeg $fileFname >$tmpimg") or die ("Error deconverting...");
system("pnmscale -xy $width $height $tmpimg") or die ("Error scalling");
system("cjpeg -smoo 10 -qual 50 >$fileFname.final") or die("Error converting");
unlink($tmpimg);


} else {$fileFname = 'noavatar.jpg'; $av_width = 128; $av_height = 128; }

?>
Ultima oară modificat Dum Feb 03, 2008 12:59 am de către ashantyk, modificat 1 dată în total.



Avatar utilizator
NooK
Average Member
Mesaje: 196
Membru din: Joi Iun 21, 2007 2:20 am

Mesajde NooK » Mie Ian 30, 2008 12:14 am

Foloseste un search s-a mai discutat de enshpe mii de ori

ashantyk
PHPRomania Supporter
Mesaje: 22
Membru din: Sâm Ian 19, 2008 10:49 pm
Localitate: Vaslui
Contact:

RE

Mesajde ashantyk » Mie Ian 30, 2008 10:28 am


Avatar utilizator
NooK
Average Member
Mesaje: 196
Membru din: Joi Iun 21, 2007 2:20 am

Mesajde NooK » Mie Ian 30, 2008 11:03 am


Avatar utilizator
Quber
Senior Member
Mesaje: 874
Membru din: Mar Iun 27, 2006 8:33 pm
Localitate: localhost
Contact:

Mesajde Quber » Mie Ian 30, 2008 12:08 pm

@NooK, el asteapta ca noi sa ne uitam in cod si sal facem el numai sa faca copy paste..!
A man who dares to waste one hour of time has not discovered the value of life.

ashantyk
PHPRomania Supporter
Mesaje: 22
Membru din: Sâm Ian 19, 2008 10:49 pm
Localitate: Vaslui
Contact:

Mesajde ashantyk » Mie Ian 30, 2008 2:56 pm

am zis si eroarea (eraore la decodare....."Error deconverting...")......... :-w mda...ms pt nik...... tot cartea te ajuta mai mult ... ca voi.........

Avatar utilizator
mihaitha
Senior Member
Mesaje: 2383
Membru din: Vin Mai 04, 2007 12:40 pm
Localitate: Sibiu
Contact:

Mesajde mihaitha » Mie Ian 30, 2008 3:48 pm


Data viitoare intreaba in alta parte. Eu unul voi refuza sa iti raspund, chiar daca voi sti raspunsul.


Înapoi la “PHP Incepători”

Cine este conectat

Utilizatori ce ce navighează pe acest forum: Niciun utilizator înregistrat și 11 vizitatori