Clase para la manipulación de imágenes con GD
Clase realizada por Daniel Mota, http://icebeat.bitacoras.com/post/279/class-image
http://icebeat.bitacoras.com/descarga/class.image.phps
<?php /* //Creamos un thumb con 200px de ancho, la altura es automatica. $thumb = new Image('directorio/imagen.jpg'); $thumb->width(200); $thumb->save(); //Crear un thumb al 50% $thumb = new Image('directorio/imagen.jpg'); $thumb->resize(50); $thumb->save(); //Cortar una porcion de la imegen $thumb = new Image('directorio/imagen.jpg'); //indicar el punto de corte $thumb->crop(0,200); //luego puedes poner el ancho y el alto que quieras $thumb->save(); //Añadir o cambiar el nombre, no hace falta indicar la extensión $thumb = new Image('directorio/imagen.jpg'); $thumb->name('imagen2'); // o tambien $thumb->name($thumb->name().'_thumb'); $thumb->width(200); $thumb->save(); */ class Image { var $file; var $image_width; var $image_height; var $width; var $height; var $ext; var $quality = 80; var $top = 0; var $left = 0; var $crop = false; var $type; function Image($name='') { $this->file = $name; $this->image_width = $info[0]; $this->image_height = $info[1]; $this->type = $this->types[$info[2]]; $this->dir = $info['dirname']; $this->ext = $info['extension']; } if(!$dir) return $this->dir; $this->dir = $dir; } function name($name='') { if(!$name) return $this->name; $this->name = $name; } function width($width='') { $this->width = $width; } function height($height='') { $this->height = $height; } function resize($percentage=50) { if($this->crop) { $this->crop = false; } else { } } function crop($top=0, $left=0) { $this->crop = true; $this->top = $top; $this->left = $left; } function quality($quality=80) { $this->quality = $quality; } function show() { $this->save(true); } function save($show=false) { if(!$this->width && !$this->height) { $this->width = $this->image_width; $this->height = $this->image_height; } else { if($this->width<=$this->height) { if($height!=$this->height) { $percentage = ($this->image_height*100)/$height; } } else { if($width!=$this->width) { $percentage = ($this->image_width*100)/$width; } } } if($this->crop) { $this->image_width = $this->width; $this->image_height = $this->height; } if($this->type=='jpeg') $image = imagecreatefromjpeg($this->file); if($this->type=='png') $image = imagecreatefrompng($this->file); if($this->type=='gif') $image = imagecreatefromgif($this->file); $new_image = imagecreatetruecolor($this->width, $this->height); imagecopyresampled($new_image, $image, 0, 0, $this->top, $this->left, $this->width, $this->height, $this->image_width, $this->image_height); $name = $show ? null: $this->dir.DIRECTORY_SEPARATOR.$this->name.'.'.$this->ext; if($this->type=='jpeg') imagejpeg($new_image, $name, $this->quality); if($this->type=='png') imagepng($new_image, $name); if($this->type=='gif') imagegif($new_image, $name); imagedestroy($image); imagedestroy($new_image); } } ?>
En PHP imagen gd por kike hace on 18/2/08 | Comentarios
