mirror of
https://github.com/Oreolek/ifhub.club.git
synced 2024-07-05 16:04:24 +03:00
Функия crop в библиотеке LiveImage/Image.php
This commit is contained in:
parent
438b544718
commit
16fb2deae5
46
engine/lib/external/LiveImage/Image.php
vendored
46
engine/lib/external/LiveImage/Image.php
vendored
|
@ -106,8 +106,10 @@ class LiveImage {
|
||||||
/**
|
/**
|
||||||
* Определяем тип файла изображения
|
* Определяем тип файла изображения
|
||||||
*/
|
*/
|
||||||
|
$size['mime']=image_type_to_mime_type($size['mime']);
|
||||||
switch ($size['mime']) {
|
switch ($size['mime']) {
|
||||||
case 'image/png':
|
case 'image/png':
|
||||||
|
case "image/x-png":
|
||||||
$tmp=imagecreatefrompng($file);
|
$tmp=imagecreatefrompng($file);
|
||||||
$this->format='png';
|
$this->format='png';
|
||||||
break;
|
break;
|
||||||
|
@ -115,7 +117,9 @@ class LiveImage {
|
||||||
$tmp=imagecreatefromgif($file);
|
$tmp=imagecreatefromgif($file);
|
||||||
$this->format='gif';
|
$this->format='gif';
|
||||||
break;
|
break;
|
||||||
case 'image/jpeg':
|
case "image/pjpeg":
|
||||||
|
case "image/jpeg":
|
||||||
|
case "image/jpg":
|
||||||
$tmp=imagecreatefromjpeg($file);
|
$tmp=imagecreatefromjpeg($file);
|
||||||
$this->format='jpg';
|
$this->format='jpg';
|
||||||
break;
|
break;
|
||||||
|
@ -196,6 +200,46 @@ class LiveImage {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Crop image
|
||||||
|
*
|
||||||
|
* @param int $width
|
||||||
|
* @param int $height
|
||||||
|
* @param int $start_width
|
||||||
|
* @param int $start_height
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function crop($width, $height, $start_width, $start_height) {
|
||||||
|
if($this->truecolor) {
|
||||||
|
$tmp=imagecreatetruecolor($width,$height);
|
||||||
|
} else {
|
||||||
|
$tmp=imagecreate($width,$height);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Если темп-изображение не создано, ставим отметку об ошикбе
|
||||||
|
*/
|
||||||
|
if(!$tmp) {
|
||||||
|
$this->set_last_error(1);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@imagesavealpha($tmp,true);
|
||||||
|
@imagealphablending($tmp,false);
|
||||||
|
|
||||||
|
if(!@imagecopyresampled($tmp,$this->image,$start_width,$start_height,$width,$height,$width,$height)) {
|
||||||
|
imagedestroy($tmp);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
imagedestroy($this->image);
|
||||||
|
$this->image=$tmp;
|
||||||
|
$this->width=$width;
|
||||||
|
$this->height=$height;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return image object
|
* Return image object
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue