<?php/** * Resize Picture * $path The width of the picture is greater than $width, and so on than the zoom * $path picture height is greater than $height cut into multiple pictures * @param $path picture address * @param $width integer|string picture width * @param @height integer|string Image height */function imgresize ($path, $width, $height) { // store the resulting picture path $imgPaths = array (); // Get picture width/height/type list ($srcW, $srcH, $type) = getimagesize ($path); $type -= 1; // Create a source image $imagecreatefromFuns = array (' Imagecreatefromgif ', ' imagecreatefromjpeg ', ' imagecreatefrompng '); $src = $ imagecreatefromfuns[$type] ($path); // the width of the picture is greater than $width zoom if ( $srcW > $width ) { $dstHeight = $srcH * ($width / $srcW); // Create a new True color image $dst = imagecreatetruecolor ( $width, $dstHeight ) ; imagecopyresampled ($dst, $src, 0, 0, 0, 0, $width , $dstHeight, $srcW, $srcH); $src = $dst; // Update the width and height of the original artwork $srcW = $width; $srcH = $dstHeight; } else { // No adjustment width $width = $srcW; } // picture height is greater than $height cut into multiple pictures if ( $srcH > $height ) { // height position of cut $srcY = 0; do { $ dstheight = ($srcY + $height > $srcH) ? ($srcH - $srcY) : ($height); $dst = imagecreatetruecolor ( $width, $dstHeight ); imagecopyresampled ($dst, $src, 0, 0, 0, $ srcy, $width, $dstHeight, $width, $dstHeight); $ filepath = './img/' . md5 (Microtime (true)) . '. jpg '; $imgPaths [] = $filePath; imagejpeg ($DST, $ FilePath) is_resource ($DST) and imagedestroy ($DST); $srcY += $dstHeight; }while ($srcY < $ SrcH); } else { // If the height of is adjusted to the original image (and possibly after the width is adjusted) Save as file $filePath = './img/' . md5 (Microtime (true)) . '. jpg '; $imgPaths [] = $filePath; imagejpeg ($src, $filePath); } // Free memory isset ($SRC) and is_resource ($SRC) and imagedestroy ($SRC); isset ($DST) and is_resource ($DST) and imagedestroy ($DST); return $imgPaths;} /** * Adjust image clarity * @param string $path picture path * @param string $quality Clarity * @return string new picture Path */function requality ( $path, $quality ) { $image _type = image_type_to_ Extension (Exif_imagetype ($path), false); $fun = "imagecreatefrom{$image _ Type} "; $src = $fun ($path); $newPath = Generateuniquefilepath ('./img/'); imagejpeg ($src, $newPath, $quality); return $newPatH;} /** * generate a unique file path * @param $basePath string folder path * @param $ suffix string * @return string file path */function generateuniquefilepath ($ basepath, $suffix = '. jpg ') { $filePath = $basePath . md5 (Microtime ( true) . $suffix; return $filePath;} Header (' content-type:image/png '); $path = '/img/jjj.jpg '; $imgPaths = imgresize ($path, 10000, 10000);// requality ($path, 1);
Use of the PHP GD library