didy Posted September 9, 2008 Report Share Posted September 9, 2008 Butu labi ja kads(a) varetu man palidzet ar bilzu samazinasanu. Ka butu vislabak samazinat bildes fikseta izmera, bet proporcionali. (PHP) Parakajos pa gogli, neko sakarigu neatradu. Ceru uz atsauciibu. Link to comment Share on other sites More sharing options...
waplet Posted September 9, 2008 Report Share Posted September 9, 2008 (edited) <?php $staly = $HTTP_POST_FILES['bil']['name']; if ($staly !='' && substr($staly, strlen($staly)-3, 3) == 'jpg' ){ // pārbaudam, vai ir saņemts pieprasījums $dirr = "liels"; //direktorija, uz kuru sūta oriģinālo bildi $dirrr = "mazs"; //direktorija, uz kuru sūta samazināto bildi $cels1= $dirr."/".$HTTP_POST_FILES['bil']['name']; //pinls ceļš uz bildi kopā ar bildes nosaukumu copy($HTTP_POST_FILES['bil']['tmp_name'], $cels1); // pārkopē lielo bildi uz direktoriju $cels= $dirrr."/".$HTTP_POST_FILES['bil']['name']; //pinls ceļš uz bildi kopā ar bildes nosaukumu $bildinfo = getimagesize($cels1); // nolasam bildes info $s_width = $bildinfo[0]; // bildes platums $s_height = $bildinfo[1]; // bildes augstums if ($s_width > $s_height){ // pārbauda, vai bilde ir horizontāli $murgs = $s_width / 50; // max bildes platums $s_width = $s_width / $murgs; // aprēķina bildes apjomus $s_height = $s_height / $murgs;// aprēķina bildes apjomus } else{ $murgs = $s_height / 50; // max bildes augtums $s_width = $s_width / $murgs; // aprēķina bildes apjomus $s_height = $s_height / $murgs; // aprēķina bildes apjomus } ini_set("memory_limit", "42M"); //uzliekam lielāku atmiņas apjomu, lai darbotos ar lielām bildēm $src_img = imagecreatefromjpeg($cels1); // iesūc atmiņā nesamazinātu bildi $dst_img = imagecreatetruecolor($s_width,$s_height); // iesūc atmiņā samazinātās bildes izmērus imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $s_width, $s_height, $bildinfo[0], $bildinfo[1]); // samazina bildi imagejpeg($dst_img,$cels); //izveido samazināto bildi imagedestroy($src_img); //nobeidz bildes procesu } ?> <form action="" method="post" enctype="multipart/form-data"> <input type="file" name="bil" /><br /> <input type="submit" value="aiziet" /> </form> <c> Mārtiņš gfx-dream.lv Edited September 9, 2008 by waplet Link to comment Share on other sites More sharing options...
mounkuls Posted September 9, 2008 Report Share Posted September 9, 2008 Slikti tad esi meklējis! Pat PHP manuālī ir tīri labs piemērs dots ar imagecopyresampled() funkciju. Ierakstiju joka pēc google php+image resize+(tavam gadijumam vēl)aspect ratio un bija gana labi. Link to comment Share on other sites More sharing options...
didy Posted September 9, 2008 Author Report Share Posted September 9, 2008 Paldies, tomer izmantosu sadu variantu! $max_width = 180; $max_height = 90; $upfile = 'up/' . $name . ''; $size = GetImageSize($upfile); $width = $size[0]; $height = $size[1]; $x_ratio = $max_width / $width; $y_ratio = $max_height / $height; if( ($width <= $max_width) && ($height <= $max_height) ) { $tn_width = $width; $tn_height = $height; } elseif (($x_ratio * $height) < $max_height) { $tn_height = ceil($x_ratio * $height); $tn_width = $max_width; } else { $tn_width = ceil($y_ratio * $width); $tn_height = $max_height; } Link to comment Share on other sites More sharing options...
Grey_Wolf Posted September 9, 2008 Report Share Posted September 9, 2008 $murgs = $s_.... njaa labie mainigo nosaukumi ... Link to comment Share on other sites More sharing options...
pilots Posted September 9, 2008 Report Share Posted September 9, 2008 Par waplet'a kodu tiešām smieklu uzsita. Link to comment Share on other sites More sharing options...
waplet Posted September 10, 2008 Report Share Posted September 10, 2008 Nav jau mans es tik ctrl+c , ctrl+v Link to comment Share on other sites More sharing options...
Recommended Posts