Código PHP:
<?php
class Imagen {
var $entrada = "";
var $width = 0;
var $height = 0;
var $tipo = 0;
function Imagen($ent) {
$this->entrada = $ent;
list($wid, $hei, $tip) = getimagesize($ent);
$this->width = $wid;
$this->height = $hei;
$this->tipo = $tip;
}
function getThumb($w, $h, $salida, $opc = false) {
$ent = $this->entrada;
$tip = $this->tipo;
$wid = $this->width;
$hei = $this->height;
if ($w) {
$newwidth = $w;
$newheight = round(($hei / $wid) * $newwidth);
} elseif ($h) {
$newheight = $h;
$newwidth = round(($wid / $hei) * $newheight);
}
// Cargar la imagen
$thumb = imagecreatetruecolor($newwidth, $newheight);
if ($tip == 1) {
$source = imagecreatefromgif($ent);
} elseif ($tip == 2) {
$source = imagecreatefromjpeg($ent);
} elseif ($tip == 3) {
$source = imagecreatefrompng($ent);
}
// Redimensionar
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $wid, $hei);
// Mostrar la nueva imagen
if ($opc) return $thumb;
else return imagejpeg($thumb, $salida);
}
function getNothumb($w, $h, $salida, $opc = false) {
$ent = $this->entrada;
$tip = $this->tipo;
$wid = $this->width;
$hei = $this->height;
if ($h) {
$newheight = $h;
$newwidth = round(($wid / $hei) * $newheight);
} else if ($w) {
$newwidth = $w;
$newheight = round(($hei / $wid) * $newwidth);
}
// Cargar la imagen
$thumb = imagecreatetruecolor($newwidth, $newheight);
if ($tip == 1) {
$source = imagecreatefromgif($ent);
} elseif ($tip == 2) {
$source = imagecreatefromjpeg($ent);
} elseif ($tip == 3) {
$source = imagecreatefrompng($ent);
}
// Redimensionar
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $wid, $hei);
// Mostrar la nueva imagen
if ($opc) return $thumb;
else return imagejpeg($thumb, $salida);
}
function getCorte($we, $he, $salida, $opc = false) {
$img = $this->entrada;
$wid = $this->width;
$hei = $this->height;
$tip = $this->tipo;
if ($wid / $we > $hei / $he) {
$hp = $hei;
$wp = round(($we / $he) * $hp);
} else {
$wp = $wid;
$hp = round(($he / $we) * $wp);
}
$lp = round(($wid - $wp) / 2);
$tp = round(($hei - $hp) / 2);
$thumb = imagecreatetruecolor($we, $he);
if ($tip == 1) {
$source = imagecreatefromgif($img);
} elseif ($tip == 2) {
$source = imagecreatefromjpeg($img);
} elseif ($tip == 3) {
$source = imagecreatefrompng($img);
}
imagecopyresampled($thumb, $source, 0, 0, $lp, $tp, $we, $he, $wp, $hp);
if ($opc) return $thumb;
else return imagejpeg($thumb, $salida);
}
}
if (isset($_GET["img"])) {
$img = new Imagen($_GET["img"]);
$tip = $_GET["tip"];
$w = $_GET["w"];
$h = $_GET["h"];
header("Content-type: image/jpeg");
if ($tip == 0) {
imagejpeg($img->getThumb($w, $h, "", true));
} elseif ($tip == 1) {
imagejpeg($img->getNothumb($w, $h, "", true));
} elseif ($tip == 2) {
imagejpeg($img->getCorte($w, $h, "", true));
}
}
?>
Código:
La direccion en la URL kedaria algo asi:Warning: getimagesize(images/prod1 /ShownDividerDPB.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /home/user/public_html/class.image.php on line 10 Warning: Cannot modify header information - headers already sent by (output started at /home/user/public_html/class.image.php:10) in /home/user/public_html/class.image.php on line 117 Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/user/public_html/class.image.php on line 104 �����JFIF���������>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality ���C� $.' ",#(7),01444'9=82<.342���C 2!!22222222222222222222222222222222222222222222222222����d�d"�������������� �������}�!1AQa"q2���#B��R��$3br� %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz����������������������������������������������������������������������������������� ������w�!1AQaq"2�B���� #3R�br� $4�%�&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz�����������������������������������������������������������������������������?����(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��
dominio.com/class.image.php?img=images/prod1+/ShownDividerDPB.jpg&tip=2&h=100&w=100
Alguna idea del porke hace esto?
![ojotes](http://static.forosdelweb.com/fdwtheme/images/smilies/ojotes.png)