简体   繁体   中英

How to get multiple size of image without using php thumb?

我已经为租船,游艇和其他车辆的预订设置了管理面板,并且我只想上载单个车辆的图像,并且需要使用phpthumb库而不是phpthumb库来调整图像的大小,因为加载列表需要花费太多时间页面,首先它使图像的缓存变得糟透了。

好的, 是一个非常好的图书馆,可以满足您的需求。

I use this function i made:

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

Pass it the original image and dimension type (different types give different sizes) and it returns the new width and height. Hope ie helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM