wallabag/inc/3rdparty/libraries/MOBIClass/ImageHandler.php

41 lines
919 B
PHP
Raw Normal View History

2014-07-24 13:49:36 +00:00
<?php
class ImageHandler {
/**
* Download an image
* @param string $url Url to the image
* @return false|string False if failed, else the data of the image (converted to grayscale jpeg)
*/
public static function DownloadImage($url){
$data = Http::Request($url);
$imgFile = @imagecreatefromstring($data);
if($imgFile !== false){
2014-07-24 19:56:04 +00:00
$result = self::CreateImage($imgFile);
imagedestroy($imgFile);
return $result;
}
return false;
}
/**
* Create an image
* @param resource $img Create an image created with createimagetruecolor
* @return false|string False if failed, else the data of the image (converted to grayscale jpeg)
*/
public static function CreateImage($img){
try{
imagefilter($img, IMG_FILTER_GRAYSCALE);
2014-07-24 13:49:36 +00:00
ob_start();
2014-07-24 19:56:04 +00:00
imagejpeg($img);
2014-07-24 13:49:36 +00:00
$image = ob_get_contents();
ob_end_clean();
return $image;
2014-07-24 19:56:04 +00:00
}catch(Exception $e){
return false;
2014-07-24 13:49:36 +00:00
}
}
}
?>