Skip to content

Commit

Permalink
Merge pull request #1 from gakowalski/gakowalski-output-to-file-patch-1
Browse files Browse the repository at this point in the history
Output cropped image to file
  • Loading branch information
seltix5 authored Dec 18, 2021
2 parents 49f9a9d + b74b58f commit cf774ac
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions smartcrop.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,22 +488,24 @@ public function crop($x, $y, $width, $height) {
return $this;
}
/**
* Output a image
* Output an image to standard output or to a file
*
* @param string $filename
*/
public function output() {
public function output($filename = null) {
$image_mime = image_type_to_mime_type(exif_imagetype($this->inputImage));

if ($image_mime === 'image/jpeg') {
header("Content-Type: image/jpeg");
imagejpeg($this->oImg);
imagejpeg($this->oImg, $filename);
}
elseif ($image_mime === 'image/png') {
header("Content-Type: image/png");
imagepng($this->oImg);
imagepng($this->oImg, $filename);
}
elseif ($image_mime === 'image/gif') {
header("Content-Type: image/gif");
imagegif($this->oImg);
imagegif($this->oImg, $filename);
}
}
/**
Expand Down

0 comments on commit cf774ac

Please sign in to comment.