ya la habia pegado en otro post... disculpen lo perdi: pero aki lo pego de nuevo, seria bueno hacer una seccion de librerias de los usuarios... o ke podamos subir las nuetras, weno ya... rollo!!
Código PHP:
<?php if (!defined('EXT')) exit;
class Image {
var $imagefile = '';
var $imageinfo = array();
var $imagebuffer = '';
var $imagesource = '';
function info($file) {
if (!is_file($file))
{
return;
}
$ext = strtolower(substr($file, strrpos($file, '.') + 1));
if (!preg_match('/^(jpe?g|png|gif)$/is', $ext))
{
return;
}
if (!function_exists('getimagesize'))
{
return;
}
$data = getimagesize($file);
if (is_array($data))
{
return array(
'extension' => $ext,
'width' => $data[0],
'height' => $data[1],
'mime' => $data['mime'],
'size' => filesize($file)
);
}
}
function _image_open($file) {
if (!is_file($file))
{
return;
}
$this->imageinfo = $this->info($file);
$fn = 'imageCreateFrom' .
str_replace('jpg', 'jpeg', $this->imageinfo['extension']);
$this->imagesource = $fn($file);
$this->imagefile = $file;
}
function _image_close($out, $q = 75) {
$fn = 'image' . str_replace('jpg', 'jpeg',
$this->imageinfo['extension']);
if (preg_match('/^jpe?g$/is', $this->imageinfo['extension']))
{
$fn($this->imagebuffer, $out, $q);
}
else
{
$fn($this->imagebuffer, $out);
}
imagedestroy($this->imagesource);
imagedestroy($this->imagebuffer);
}
function _image_apply_alpha($r = 0, $g = 0, $b = 0, $alpha = 127) {
if ($this->imageinfo['extension'] == 'png')
{
$this->imageinfo['alpha'] = imageColorAllocateAlpha($this->imagebuffer,
$r, $g, $b, $alpha);
imagealphablending($this->imagebuffer, FALSE);
imagefilledrectangle($this->imagebuffer, 0, 0,
imagesx($this->imagebuffer), imagesy($this->imagebuffer),
$this->imageinfo['alpha']);
imagealphablending($this->imagebuffer, TRUE);
imagesavealpha($this->imagebuffer, TRUE);
}
}
function resize($input, $output, $width, $height) {
$this->_image_open($input);
$this->_image_source_resize($width, $height);
$this->_image_close($output);
}
function _image_source_resize($width, $height) {
$this->imagebuffer = imagecreatetruecolor($width, $height);
$this->_image_apply_alpha();
imagecopyresampled($this->imagebuffer,
$this->imagesource, 0, 0, 0, 0,
$width, $height, $this->imageinfo['width'], $this->imageinfo['height']);
}
function rotate($input, $output, $deg = 90) {
$this->_image_open($input);
$this->_image_source_rotate($deg);
$this->_image_close($output);
}
function _image_source_rotate($deg, $bg = 0x000000) {
if (!function_exists('imageRotate'))
{
return;
}
$this->imagebuffer =
imageRotate($this->imagesource, $deg, $bg);
}
function thumb($input, $output, $width, $height = FALSE) {
if ($height === FALSE)
{
$height = $width;
}
$this->_image_open($input);
$test = max($width / $this->imageinfo['width'],
$height / $this->imageinfo['height']);
$this->_image_source_resize($this->imageinfo['width'] * $test,
$this->imageinfo['height'] * $test);
$x = round(($this->imageinfo['width'] * $test - $width) / 2);
$y = round(($this->imageinfo['height'] * $test - $height) / 2);
$this->imagesource = $this->imagebuffer;
$this->_image_source_copy($width, $height, $x, $y);
$this->_image_close($output);
}
function scale($input, $output, $width, $height = FALSE) {
$this->_image_open($input);
if ($height === FALSE)
{
$height = round(($width * $this->imageinfo['height']) / 100, 0);
$width = round(($width * $this->imageinfo['width']) / 100, 0);
}
else {
$test = $this->imageinfo['height'] / $this->imageinfo['width'];
if ($test < $height / $width)
{
$width = (int)min($width, $this->imageinfo['width']);
$height = (int)round($width * $test);
}
else {
$height = (int)min($height, $this->imageinfo['height']);
$width = (int)round($height / $test);
}
}
$this->_image_source_resize($width, $height);
$this->_image_close($output);
}
function crop($input, $output, $width, $height, $x = 0, $y = 0) {
$this->_image_open($input);
$this->_image_source_copy($width, $height, $x, $y);
$this->_image_close($output);
}
function _image_source_copy($width, $height, $x = 0, $y = 0) {
$this->imagebuffer = imageCreateTrueColor($width, $height);
$this->_image_apply_alpha();
imagecopy($this->imagebuffer, $this->imagesource,
0, 0, $x, $y, $width, $height);
}
}
?>
es una libreria que empeze hace un poco... pero funciona, de hecho intentare integrar lo ke he aprendido de esto... imagenes de error... o alternativas ((como alt="" mas atractivos))
si te sirve, gracias...