コード例 #1
0
 public function interpolation(string $method = 'bilinear_fixed') : InternalGD
 {
     imagesetinterpolation($this->canvas, Converter::toConstant($method, 'IMG_'));
     return $this;
 }
コード例 #2
0
ファイル: zap-stream.php プロジェクト: johnnysacrifice/zap
 private function alpha()
 {
     imagesetinterpolation($this->resource(), IMG_BILINEAR_FIXED);
     imagealphablending($this->resource, false);
     imagesavealpha($this->resource, true);
 }
コード例 #3
0
 static function resize($sourcePath, $newWidth = 100, $newHeight = 100)
 {
     // Create image resource from source path
     switch (exif_imagetype($sourcePath)) {
         case IMAGETYPE_JPEG:
             $sourceImage = imagecreatefromjpeg($sourcePath);
             break;
         case IMAGETYPE_PNG:
             $sourceImage = imagecreatefrompng($sourcePath);
             break;
         case IMAGETYPE_GIF:
             $sourceImage = imagecreatefromgif($sourcePath);
             break;
         default:
             return;
     }
     // Create the new image (still blank/empty)
     $newImage = imagecreatetruecolor($newWidth, $newHeight);
     imagesetinterpolation($newImage, IMG_SINC);
     // Determine the source image Dimensions
     $sourceImageWidth = imagesx($sourceImage);
     $sourceImageHeight = imagesy($sourceImage);
     $sourceImageAspectRatio = $sourceImageWidth / $sourceImageHeight;
     $newImageAspectRatio = $newWidth / $newHeight;
     // Determine parameters and copy part of the source image into the new image
     if ($newImageAspectRatio >= $sourceImageAspectRatio) {
         // width is the limiting factor for the source image
         $src_x = 0;
         $src_w = $sourceImageWidth;
         $src_h = $src_w / $newImageAspectRatio;
         $src_y = ($sourceImageHeight - $src_h) / 2;
     } else {
         // height of source image is limiting factor
         $src_y = 0;
         $src_h = $sourceImageHeight;
         $src_w = $src_h * $newImageAspectRatio;
         $src_x = ($sourceImageWidth - $src_w) / 2;
     }
     imagecopyresampled($newImage, $sourceImage, 0, 0, $src_x, $src_y, $newWidth, $newHeight, $src_w, $src_h);
     // Save new image to destination path
     switch (exif_imagetype($sourcePath)) {
         case IMAGETYPE_JPEG:
             imagejpeg($newImage, $sourcePath, 100);
             break;
         case IMAGETYPE_PNG:
             imagepng($newImage, $sourcePath);
             break;
         case IMAGETYPE_GIF:
             imagegif($newImage, $sourcePath);
             break;
     }
     // Remove image resources to reallocate space
     imagedestroy($sourceImage);
     imagedestroy($newImage);
 }