2016-08-18 20:39:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------
|
|
|
|
|
|
|
|
Chevereto
|
|
|
|
http://chevereto.com/
|
|
|
|
|
|
|
|
@author Rodolfo Berrios A. <http://rodolfoberrios.com/>
|
2018-08-16 18:51:52 +00:00
|
|
|
<inbox@rodolfoberrios.com>
|
2016-08-18 20:39:31 +00:00
|
|
|
|
|
|
|
Copyright (C) Rodolfo Berrios A. All rights reserved.
|
2018-08-16 18:51:52 +00:00
|
|
|
|
2016-08-18 20:39:31 +00:00
|
|
|
BY USING THIS SOFTWARE YOU DECLARE TO ACCEPT THE CHEVERETO EULA
|
|
|
|
http://chevereto.com/license
|
|
|
|
|
|
|
|
--------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
namespace CHV;
|
2018-08-16 18:51:52 +00:00
|
|
|
|
|
|
|
use G;
|
|
|
|
use Exception;
|
2016-08-18 20:39:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This could be used to extend the image types allowed... Maybe .tiff support and so on.
|
|
|
|
*/
|
2018-08-16 18:51:52 +00:00
|
|
|
class ImageConvert
|
|
|
|
{
|
|
|
|
public function __construct($source, $to, $destination, $quality=90)
|
|
|
|
{
|
|
|
|
$source_info = G\get_image_fileinfo($source);
|
|
|
|
switch ($source_info['extension']) {
|
|
|
|
case 'bmp':
|
|
|
|
$temp_image = function_exists('imagecreatefrombmp') ? imagecreatefrombmp($source) : G\imagecreatefrombmp($source);
|
|
|
|
break;
|
|
|
|
case 'jpg':
|
|
|
|
$temp_image = imagecreatefromjpeg($source);
|
|
|
|
break;
|
|
|
|
case 'gif':
|
|
|
|
$temp_image = imagecreatefromgif($source);
|
|
|
|
break;
|
|
|
|
case 'png':
|
|
|
|
$temp_image = imagecreatefrompng($source);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return $source;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$temp_image) {
|
|
|
|
return $source;
|
|
|
|
}
|
|
|
|
|
|
|
|
unlink($source);
|
2016-08-18 20:39:31 +00:00
|
|
|
|
2018-08-16 18:51:52 +00:00
|
|
|
switch ($to) {
|
|
|
|
case 'jpg':
|
|
|
|
imagejpeg($temp_image, $destination, $quality);
|
|
|
|
break;
|
|
|
|
case 'gif':
|
|
|
|
imagegif($temp_image, $destination);
|
|
|
|
break;
|
|
|
|
case 'png':
|
|
|
|
imagepng($temp_image, $destination);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return $source;
|
|
|
|
break;
|
|
|
|
}
|
2016-08-18 20:39:31 +00:00
|
|
|
|
2018-08-16 18:51:52 +00:00
|
|
|
$this->out = $destination;
|
|
|
|
}
|
|
|
|
}
|