1

我已经为包机、游艇和其他车辆预订设置了一个管理面板,我只想为车辆上传一张图片,并且需要在不使用 phpthumb 库的情况下调整多种尺寸的图片,因为加载列表需要太多时间页面,首先它会缓存图像,因此它很烂。我需要一种简单的方法来调整单个图像的大小,这样管理员就不必上传该车辆的多个图像。

4

2 回答 2

0

好的,这是一个非常好的库,可以满足您的需要。

于 2012-05-03T13:38:25.427 回答
0

我使用我制作的这个功能:

<?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 );
}
?>

将原始图像和尺寸类型传递给它(不同的类型给出不同的尺寸)并返回新的宽度和高度。希望即有帮助。

于 2012-05-03T13:41:26.557 回答