Such page {code...} is different in width of each image. Is there any way to get the height of each image. And fill in the height field? Ask for advice! Such a page
...
The width of each image is different. Is there any way to get the height of each image. And fill in the height field?
Ask for advice!
Reply content:
Such a page
...
The width of each image is different. Is there any way to get the height of each image. And fill in the height field?
Ask for advice!
The getimagesize function of PHP can obtain the image width and height information.
array getimagesize ( string $filename [, array &$imageinfo ] )
Returns an array with four units. Index 0 contains the pixel value of the image width, and index 1 contains the pixel value of the Image Height. Index 2 is the mark of the image type: 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF (intel byte order), 8 = TIFF (motorola byte order), 9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF, 15 = WBMP, 16 = XBM. These tags correspond to the newly added IMAGETYPE constant in PHP 4.3.0. Index 3 is a text string with the content "height =" yyy "width =" xxx "and can be directly used for IMG marking.
This is the PHP official site manual: http://php.net/manual/en/function.get...
Add a demo:
$images_array = array("http://static.zend.com/img/logo.gif");foreach($images_array as $image){list($width, $height, $type, $attr) = getimagesize($image);$new_height = (int)(192 / $width * $height);echo '
';}
Do you want to fix the image to a box...
// Image Adaptive // function image_fix_to_box (obj, width, height) {var oWidth = obj. width; var oHeight = obj. height; var r1 = parseFloat (obj. width)/parseFloat (obj. height); var r2 = parseFloat (width)/parseFloat (height); if (Math. abs (r1-r2) <0.0001) {obj. width = width; obj. height = height;} else if (r1 <r2) {obj. height = height; obj. width = parseInt (parseFloat (height)/parseFloat (oHeight) * oWidth);} else {obj. width = width; obj. height = parseInt (parseFloat (width)/parseFloat (oWidth) * oHeight );}}
Two Methods of jquery have been found:
1, http://www.cssrain.cn /? P = 108
2, http://www.hake.cc/a/biancheng/web/js...