Home >php教程 >php手册 >返回最佳图片的高度宽度

返回最佳图片的高度宽度

WBOY
WBOYOriginal
2016-06-21 09:05:59792browse
  •  //返回最佳图片的高度,宽度。以及原来的高度和宽度
    //$SrcH:原高度,$SrcW:原宽度,$DstH:目标高度,$DstW:目标宽度
    //调用时用 list($SrcW,$SrcH,$DstW,$DstH) = RtImageSize($ImgFile,200,200)
    function RtImageSize($ImgFile,$ImgW,$ImgH
    )
    {
            if(
    file_exists($ImgFile
    ))
            {
            
    $Size = @GetImageSize($ImgFile
    );
            
    $SrcW $Size[0
    ];
            
    $SrcH $Size[1
    ];
            
    $Ratio max($SrcW/$ImgW,$SrcH/$ImgH
    );
            
    $DstW = ($SrcW $Ratio
    );
            
    $DstH = ($SrcH $Ratio
    );
            }
            return array(
    $SrcW,$SrcH,$DstW,$DstH
    );
    }  


  • Statement:
    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