<?php
/**
* Description of PicSet
*
* Работи със jpeg, gif и png
* Клас за проверка на една снимка, дали е потретна, пейзажна или квадрат.
* Връща данни за снимката като директория, име, тип, височина и ширина
* Също така и преоразмерява снимката като запазва съотношението и/или създава черно-бяло копие.
*
* @author hankrum
*/
class PicSet {
private $destination; //Път до изображението
private $size; //Максимална височина или широчина на изображението
private $type; //Типа снимка
private $post_width;
private $post_height;
public function __construct($destination) {
$this->destination = $destination;
} else {
echo 'Неподдържан формат, само jpeg(jpeg), gif и png!!!';
}
} else {
echo 'Това не е изображение!!!';
}
}
public function get_type() {
return $this->type;
}
public function get_dir() {
return $this->setDIR();
}
public function get_name() {
return $this->setNAME();
}
public function get_height() {
return $this->setY();
}
public function get_width() {
return $this->setX();
}
public function intIMG_profil() {
if ($this->setX() > $this->setY()) {//Ако снимката е пейзажна
return 2;
} elseif ($this->setY() > $this->setX()) {//Ако снимката е портретна
return 1;
} elseif ($this->setY() == $this->setX()) {//Ако снимката е квадрат
return 0;
}
}
public function resizeIMG($size = 100, $bw = false) {
$this->size = $size;
$method = 'resize_' . $this->type;
return $this->$method($bw);
}
private function setDIR() {
$dir = dirname($this->destination); //Дава директорията return $dir;
}
private function setNAME() {
$name = basename($this->destination); //Дава името на изображението return $name;
}
private function setX() { //Определя широчината
return $width;
}
private function setY() { //Определя височината
$height = imagesy($this->setIMG()); return $height;
}
private function reIMG() { //Задава съотношението и оразмерява
if ($this->intIMG_profil() == 2) {//Ако снимката е пейзажна
$this->post_height = floor($this->setY() * ($this->size / $this->setX())); $this->post_width = $this->size;
} elseif ($this->intIMG_profil() == 1) {//Ако снимката е портретна
$this->post_width = floor($this->setX() * ($this->size / $this->setY())); $this->post_height = $this->size;
} elseif ($this->intIMG_profil() == 0) {//Ако снимката е квадрат
$this->post_height = $this->size;
$this->post_width = $this->size;
}
}
private function setIMG() { //Създава копие със същите размери
$method = 'imagecreatefrom' . $this->type;
$img = $method($this->destination);
return $img;
}
private function resize_jpeg($bw = false) {
$this->reIMG();
//Оразмеряване на изображението
imagecopyresized($tmpp_img, $this->setIMG(), 0, 0, 0, 0, $this->post_width, $this->post_height, $this->setX(), $this->setY()); if ($bw === true) { // Създава чернобяло копие
}
imagejpeg($tmpp_img, $this->setDIR() . DIRECTORY_SEPARATOR . $this->setNAME()); }
private function resize_png($bw = false) {
$this->resize_gif_png();
}
private function resize_gif($bw = false) {
$this->resize_gif_png();
}
private function resize_gif_png() {
$this->reIMG();
//Оразмеряване на изображението
imagecopyresized($tmpp_img, $this->setIMG(), 0, 0, 0, 0, $this->post_width, $this->post_height, $this->setX(), $this->setY()); if ($bw === true) {
}
$function = 'image' . $this->type;
$function($tmpp_img, $this->setDIR() . DIRECTORY_SEPARATOR . $this->setNAME());
}
}