首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在不使用php拇指的情况下获得多种尺寸的图片?

如何在不使用php拇指的情况下获得多种尺寸的图片?
EN

Stack Overflow用户
提问于 2012-05-03 21:35:50
回答 2查看 421关注 0票数 1

我已经设置了一个包机,游艇和其他车辆预订的管理面板,我只想上传一个单一的图像为车辆和nedd来调整图像的多个大小,而不使用phpthumb库,因为它需要太多的时间加载列表页面,首先它使图像的缓存,因此它糟糕。我需要一个简单的方法来调整单个图像的大小,以便管理员没有上传该车辆的多个图像。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-05-03 21:38:25

好的,this是一个非常好的库,用来做你需要的事情。

票数 0
EN

Stack Overflow用户

发布于 2012-05-03 21:41:27

我使用我创建的这个函数:

代码语言:javascript
复制
<?php
function getImageXY( $image, $type='original' ) {
    if( $type == 'original' ) {
        $imgDimsMax = 200;
    } else if( $type == 'thumb' ) {
        $imgDimsMax = 60;
    } else if( $type == 'defualt' ) {
        $imgDimsMax = 140;
    }

    $aspectRatio = 1;    // deafult aspect ratio...keep the image as is.

    // set the default dimensions.
    $imgWidth   = $imgDimsMax;
    $imgHeight  = $imgDimsMax;

    list( $width, $height, $type, $attr ) = getimagesize( $image );
    //$imgHeight    = floor ( $height * ( $imgWidth / $width ) );

    if( $width == $height ) {
        // if the image is less than ( $imgDimsMax x $imgDimsMax ), use it as is..
        if( $width < $imgDimsMax ) {
            $imgWidth   = $width;
            $imgHeight  = $height;
        }
    } else {
        if( $width > $height ) {
            // set $imgWidth to $imgDimsMax and resize $imgHeight proportionately
            $aspectRatio    = $imgWidth / $width;
            $imgHeight      = floor ( $height * $aspectRatio );
        } else if( $width < $height ) {
            // set $imgHeight to $imgDimsMax and resize $imgWidth proportionately
            $aspectRatio    = $imgHeight / $height;
            $imgWidth       = floor ( $width * $aspectRatio );
        }
    }

    return array( $imgWidth, $imgHeight );
}
?>

向它传递原始图像和尺寸类型(不同的类型指定不同的大小),它将返回新的宽度和高度。希望ie能帮上忙。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10432542

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档