50 lines
1.2 KiB
PHP
50 lines
1.2 KiB
PHP
|
|
<?php
|
||
|
|
/**
|
||
|
|
* Image Input Output Tools
|
||
|
|
*/
|
||
|
|
class ImgIOTools {
|
||
|
|
public static $maxScreenWidth = 1067; //screen dimensions
|
||
|
|
|
||
|
|
public static $maxScreenHeight = 600;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Flushes image to screen
|
||
|
|
* @param Imagick $im
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public static function onScreen(Imagick $img) {
|
||
|
|
$img->scaleImage(self::$maxScreenWidth, self::$maxScreenHeight, true);
|
||
|
|
|
||
|
|
//$img = self::scaleByLength($img, $this->maxScreenWidth, $this->maxScreenHeight);
|
||
|
|
header('Content-type: image/' . ZAP_IMG_TYPE);
|
||
|
|
echo $img->getImageBlob();
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Puts image from $imgUrl (if exists) onscreen
|
||
|
|
* @param string $imgUrl
|
||
|
|
* @return boolean or imagedata
|
||
|
|
*/
|
||
|
|
public static function urlOnScreen($imgUrl) {
|
||
|
|
if (file_exists($imgUrl)) {
|
||
|
|
$img = new Imagick($imgUrl);
|
||
|
|
self::onScreen($img);
|
||
|
|
} else {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Saves active image from $im as $filename.$filetype in $folder
|
||
|
|
* @param Imagick $im
|
||
|
|
* @param string $folder
|
||
|
|
* @param string $filename
|
||
|
|
* @param string $filetype
|
||
|
|
* @return boolean
|
||
|
|
*/
|
||
|
|
public static function saveImg(Imagick $img, $folder, $filename) {
|
||
|
|
$path = $folder . $filename . '.' . ZAP_IMG_TYPE;
|
||
|
|
return $img->writeImage($path);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
?>
|