javascript - PHP或js获取图片的高度

WBOY
Release: 2016-06-06 20:52:19
Original
818 people have browsed it

这样的页面

Copy after login
Copy after login
  • javascript - PHP或js获取图片的高度
  • javascript - PHP或js获取图片的高度 ...
  • javascript - PHP或js获取图片的高度
  • javascript - PHP或js获取图片的高度

    每个图片宽度都不一样。有什么方法可以获取到每张图片的高度。并且填到height里面去?
    求教!

    回复内容:

    这样的页面

    Copy after login
    Copy after login
  • javascript - PHP或js获取图片的高度
  • javascript - PHP或js获取图片的高度 ...
  • javascript - PHP或js获取图片的高度
  • javascript - PHP或js获取图片的高度

    每个图片宽度都不一样。有什么方法可以获取到每张图片的高度。并且填到height里面去?
    求教!

    PHP的函数getimagesize可以得到图片的宽高等信息

    array getimagesize ( string $filename [, array &$imageinfo ] )
    Copy after login

    返回一个具有四个单元的数组。索引 0 包含图像宽度的像素值,索引 1 包含图像高度的像素值。索引 2 是图像类型的标记: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。这些标记与 PHP 4.3.0 新加的 IMAGETYPE 常量对应。索引 3 是文本字符串,内容为“height="yyy" width="xxx"”,可直接用于 IMG 标记。

    这是PHP官网的手册:http://php.net/manual/en/function.get...

    补充一个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 '
    Copy after login
  • javascript - PHP或js获取图片的高度'; }

    你是要把图片固定到一个框里面去么。。。

    //图片自适应
    //<img  src="xxxxx" onload="javascript:image_fix_to_box(this,192,128);" alt="javascript - PHP或js获取图片的高度" >
    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) 
                                
                <p class="answer fmt" data-id="1020000000097727">
                                        </p><p>已经找到了jquery的两种方法:<br>
    1,http://www.cssrain.cn/?p=108<br>
    2,http://www.hake.cc/a/biancheng/web/js...</p>
                                
    Copy after login
  • Related labels:
    source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!