תמונה פרופציונית

orenphp

New member
תמונה פרופציונית

נגיד אתם רוצים לקחת תמונה אשר מידותיה הן: 145*200 ולהציג אותה כך שהמקסימום (גובה או רוחב) יהיה 45 ועדיין לשמור על צורה נורמלית של תמונה ללא כיווץ לא פרופרציוני אשר יגרום לתמונה להראות מגוחך. ניסיתי למצוא פתרון לבעיה ואומנם מצאתי פונקציה אשר עושה זאת , היא מוצגת לפניכם, אם יש לכם רעיונות נוספים לעשיית הדבר אנא שתפו אותי. <div align=right dir=ltr> function imageproportaion($imagepath) { //tnx to http://px.sklar.com/ ! $picsize = 45; //max 45 $size = getimagesize($imagepath); $pic[height] = $size[1]; $pic[width] = $size[0]; while($pic[width] > $picsize){ $pic[width] = $pic[width] * .5; $widthreduce++; } for($heightreduce = 0; $heightreduce < $widthreduce; $heightreduce++){ $pic[height] = $pic[height] * .5; } while($pic[height] > $picsize){ $pic[height] = $pic[height] * .5; $heightreduce++; } for($widthreduce=$widthreduce; $widthreduce < $heightreduce; $widthreduce++){ $pic[width] = $pic[width] * .5; } $pic[height] = (int)$pic[height]; $pic[width] = (int)$pic[width]; return $pic; }
 

orenphp

New member
הצגה נוחה יותר של הפונקציה :)

function imageproportaion($imagepath) { //tnx to http://px.sklar.com/ ! $picsize = 45; //max 45 $size = getimagesize($imagepath); $pic[height] = $size[1]; $pic[width] = $size[0]; while($pic[width] > $picsize){ $pic[width] = $pic[width] * .5; $widthreduce++; } for($heightreduce = 0; $heightreduce < $widthreduce; $heightreduce++){ $pic[height] = $pic[height] * .5; } while($pic[height] > $picsize){ $pic[height] = $pic[height] * .5; $heightreduce++; } for($widthreduce=$widthreduce; $widthreduce < $heightreduce; $widthreduce++){ $pic[width] = $pic[width] * .5; } $pic[height] = (int)$pic[height]; $pic[width] = (int)$pic[width]; return $pic; }​
 

orenphp

New member
זה עובד גם ככה..... רק רציתי

לשמוע עוד רעיונות ואולי דרכים יותר יעילות וטובות לבצא את הפעולה. הפונקציה הכתובה עובדת מצוין.
 
למעלה