Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Imagedetail {
- private $width;
- private $height;
- private $path;
- public function __construct($width, $height, $path) {
- $this->width = $width;
- $this->height = $height;
- $this->path = $path;
- }
- public function setWidth($width) {
- $this->width = $width;
- }
- public function getWidth() {
- return $this->width;
- }
- public function setHeight($height) {
- $this->height = $height;
- }
- public function getHeight() {
- return $this->height;
- }
- public function setPath($path) {
- $this->path = $path;
- }
- public function getPath() {
- return $this->path;
- }
- }
- class Imageserver {
- private $image;
- private $image_type;
- function load($filename) {
- $image_info = getimagesize($filename);
- $this->image_type = $image_info[2];
- if ($this->image_type == IMAGETYPE_JPEG) {
- $this->image = imagecreatefromjpeg($filename);
- } elseif ($this->image_type == IMAGETYPE_GIF) {
- $this->image = imagecreatefromgif($filename);
- } elseif ($this->image_type == IMAGETYPE_PNG) {
- $this->image = imagecreatefrompng($filename);
- }
- }
- function save($originalFile, $filename, $permissions) {
- if ($permissions != null) {
- chmod($originalFile, $permissions);
- }
- if ($this->image_type == IMAGETYPE_JPEG) {
- imagejpeg($this->image, $filename, 75);
- } elseif ($this->image_type == IMAGETYPE_GIF) {
- imagegif($this->image, $filename);
- } elseif ($this->image_type == IMAGETYPE_PNG) {
- imagepng($this->image, $filename);
- }
- }
- function output($image_type) {
- if ($image_type == IMAGETYPE_JPEG) {
- imagejpeg($this->image);
- } elseif ($image_type == IMAGETYPE_GIF) {
- imagegif($this->image);
- } elseif ($image_type == IMAGETYPE_PNG) {
- imagepng($this->image);
- }
- }
- function getWidth() {
- return imagesx($this->image);
- }
- function getHeight() {
- return imagesy($this->image);
- }
- function resizeToHeight($height) {
- $ratio = $height / $this->getHeight();
- $width = $this->getWidth() * $ratio;
- $this->resize($width, $height);
- }
- function resizeToWidth($width) {
- $ratio = $width / $this->getWidth();
- $height = $this->getheight() * $ratio;
- $this->resize($width, $height);
- }
- function scale($scale) {
- $width = $this->getWidth() * $scale / 100;
- $height = $this->getheight() * $scale / 100;
- $this->resize($width, $height);
- }
- function resize($width, $height) {
- $new_image = imagecreatetruecolor($width, $height);
- imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
- $this->image = $new_image;
- }
- function setImageType($image_type) {
- $this->image_type = $image_type;
- }
- function getImageType() {
- return $this->image_type;
- }
- function setImage($image) {
- $this->image = $image;
- }
- function getImage() {
- return $this->image;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement