PHP Thumbnail Image Resizing with proportions

后端 未结 6 2211
终归单人心
终归单人心 2020-12-06 15:06

As a brief run down, I am currently making a dating type site. Users can create accounts and upload profile pictures (up to 8). In order to display these in the browse area

6条回答
  •  醉酒成梦
    2020-12-06 15:22

    Some says imagic faster, i use next

        
        function resizeImageProportional($imagePath, $destinationPath, $width = false, $height = false, $filterType = \Imagick::FILTER_POINT, $blur = 1, $bestFit = false, $cropZoom = false)
        {
            if (!$width && !$height) {
                trigger_error("WTF_IMAGE_RESIZE");
                return false;
            }
            //The blur factor where > 1 is blurry, < 1 is sharp.
            $imagick = new \Imagick(realpath($imagePath));

    if (!$width || !$height) { $orig_width = $imagick->getImageWidth(); $orig_height = $imagick->getImageHeight(); $proportion = $orig_height/$orig_width; if (!$width) { $width = $height*$proportion; } elseif (!$height) { $height = $width*$proportion; } } if ($bestFit) { $imagick->resizeImage($width, $height, $filterType, $blur, $bestFit); } else { $imagick->resizeImage($width, $height, $filterType, $blur); } if ($cropZoom) { $cropWidth = $imagick->getImageWidth(); $cropHeight = $imagick->getImageHeight(); $newWidth = $cropWidth / 2; $newHeight = $cropHeight / 2; $imagick->cropimage( $newWidth, $newHeight, ($cropWidth - $newWidth) / 2, ($cropHeight - $newHeight) / 2 ); $imagick->scaleimage( $imagick->getImageWidth() * 4, $imagick->getImageHeight() * 4 ); }

提交回复
热议问题