अब कुछ चौड़ाई उदाहरण के साथ लगभग नगण्य के बाद मेरे क्लासिक बीजगणित कौशल बदले में में लात मारी।
अगर मैं चौड़ाई ले लिया और ऊंचाई से यह विभाजित इस मामले में ऐसा है, तो, 460/280 आप 1.642 मिलता है ... जो उस क्षेत्र का पहलू अनुपात है, अब अगर मैंने छवि के पहलू अनुपात को देखा, तो मुझे पता था कि अगर यह 1.642 से अधिक था ... जिसका मतलब है कि यह क्षेत्र से बड़ा था, और यदि छवि का पहलू अनुपात कम था इससे, यह लंबा था।
तो मैं
// Set the Image in question
$image = 'img/gif/b47rz.gif';
// Set the width of the area and height of the area
$inputwidth = 460;
$inputheight = 280;
// Get the width and height of the Image
list($width,$height) = getimagesize($image);
// So then if the image is wider rather than taller, set the width and figure out the height
if (($width/$height) > ($inputwidth/$inputheight)) {
$outputwidth = $inputwidth;
$outputheight = ($inputwidth * $height)/ $width;
}
// And if the image is taller rather than wider, then set the height and figure out the width
elseif (($width/$height) < ($inputwidth/$inputheight)) {
$outputwidth = ($inputheight * $width)/ $height;
$outputheight = $inputheight;
}
// And because it is entirely possible that the image could be the exact same size/aspect ratio of the desired area, so we have that covered as well
elseif (($width/$height) == ($inputwidth/$inputheight)) {
$outputwidth = $inputwidth;
$outputheight = $inputheight;
}
// Echo out the results and done
echo '<img src="'.$image.'" width="'.$outputwidth.'" height="'.$outputheight.'">';
निम्नलिखित के साथ आया था, और यह पूरी तरह से काम किया है, तो मैंने सोचा कि मैं हिस्सा होगा, उम्मीद है कि यह कुछ लोगों को
स्रोत
2012-06-18 19:24:29
मैं बात इस तरह की संभाल करने के लिए एक jQuery प्लगइन लिखा है, शायद यह मदद मिलेगी: http://stackoverflow.com/questions/ 18838 9 63/आनुपातिक-पैमाने पर-iframe-to-fit-in-a-div-use-jquery/25222380 # 25222380 –