Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class SimpleImage {
- function __construct($filename) {
- $this->image = new Imagick($filename);
- $this->filename = $filename;
- $this->compression = 85;
- }
- function setCompression($compression) {
- if(!is_numeric($compression) || $compression < 0 || $compression > 100) {
- throw new Exception("Invalid compression value!");
- }
- $this->compression = $compression;
- }
- function save($newFileName) {
- $this->image->setCompression($this->compression);
- if(is_string($newFileName)) {
- $this->image->writeImage($newFileName);
- }
- else {
- $this->image->writeImage($this->filename);
- }
- }
- function output() {
- echo file_get_contents($this->filename);
- }
- function getWidth() {
- return $this->image->getImageWidth();
- }
- function getHeight() {
- return $this->image->getImageHeight();
- }
- 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) {
- return $this->image->scaleImage($width, $height);
- }
- function rotate($angle = 90) {
- $this->image->rotateImage(new ImagickPixel(), 90);
- }
- function crop($width, $height, $x, $y) {
- $this->image->cropImage($width, $height, $x, $y);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment