10 const IMAGE_SCALE_INSIDE = 1;
11 const IMAGE_SCALE_ONLY_SMALLER = 2;
20 return imagecreatefromstring(file_get_contents($filename));
29 public static function dataUri($image,$type = IMAGETYPE_JPEG,$quality = 75){
33 imagepng($image,null,$quality);
39 imagejpeg($image,null,$quality);
45 return 'data:' . image_type_to_mime_type($type) .
';base64,' . base64_encode(ob_get_clean());
57 public static function scaleBox($image,$width,$height,$options = 0,$mode = IMG_BILINEAR_FIXED){
58 $x_factor = $width / ($orig_width = imagesx($image));
59 $y_factor = $height / ($orig_height = imagesy($image));
60 $factor = $options & self::IMAGE_SCALE_INSIDE ? min($x_factor,$y_factor) : max($x_factor,$y_factor);
61 if(($options & self::IMAGE_SCALE_ONLY_SMALLER) && ($factor >= 1))
return false;
62 return imagescale($image,$orig_width * $factor,$orig_height * $factor,$mode);
static scaleBox($image, $width, $height, $options=0, $mode=IMG_BILINEAR_FIXED)
Scale an image resource to fit a certain box size, maintaining aspect ratio.
static dataUri($image, $type=IMAGETYPE_JPEG, $quality=75)
Convert an image resource to base64 encoded uri.
static fromFile($filename)
Create an image resource from file.