Skip to main content
Version: Fegg 5.x

Trim::setImage

Set the source image and the output path

Description​

public void Trim::setImage( string $org_path, string $cnv_path )

Loads the source image. The output format is decided by the extension of $cnv_path: jpg (or jpeg), png or gif. A JPEG photo is turned the way its Exif orientation says.

Throws a \RuntimeException when:

  • $org_path is not a file;
  • the extension of $cnv_path is not jpg, jpeg, png or gif;
  • $org_path is not a JPEG, PNG or GIF image, or cannot be read.

Arguments​

NameData typeDefaultRemarks
$org_pathstringSource image path
$cnv_pathstringOutput image path (.jpg, .jpeg, .png or .gif)

Example​

Controller
use Fegg\Tool\Trim;

$trim = new Trim();
try {
$trim->setImage('path/to/image.jpg', 'path/to/converted.jpg');
} catch (\RuntimeException $e) {
// missing file, not an image, or another output type
}