Ver Mensaje Individual
  #1 (permalink)  
Antiguo 13/10/2004, 08:51
martindaguerre
 
Fecha de Ingreso: enero-2004
Ubicación: Montevideo
Mensajes: 7
Antigüedad: 20 años, 2 meses
Puntos: 0
Información UPLOAD de JPG y Resize en el servidor tengo esto pero se ven feas...¿que pasa?

Intento hacer UPLOAD de JPG y Resize en el servidor ...
ya pude, esto funciona pero se ven feas...¿que pasa?

Este es el codigo que estoy usando ...
Algúna sugerencia...
o otra forma...
Esto genera una copia en munuatura del jpg...
__________________________________________________ ____________

<?php
/*
EJ:
thumb.php?image=fotocargada.jpg&x=200&y=200
*/
error_reporting(0);

$types = array (1 => "gif", "jpeg", "png", "swf", "psd", "wbmp");

define ('./', './');

$cachedir = substr($HTTP_GET_VARS['image'],0,strrpos($HTTP_GET_VARS['image'],'/') + 1).m;
!is_dir ($cachedir)
? mkdir ($cachedir, 0777)
: system ("chmod 0777 ".$cachedir);

(!isset ($x) || ereg ('^[0-9]{1,}$', $x, $regs)) &&
(!isset ($y) || ereg ('^[0-9]{1,}$', $y, $regs)) &&
(isset ($x) || isset ($y))
? true
: DIE ('¡Faltando o los parámetros del tamaño no válido!');

!isset ($resize) || !ereg ('^[0|1]$', $resize, $regs)
? $resize = 0
: $resize;

!isset ($aspectratio) || !ereg ('^[0|1]$', $aspectratio, $regs)
? isset ($x) && isset ($y)
? $aspectratio = 1
: $aspectratio = 0
: $aspectratio;

!isset ($image)
? DIE ('¡No se declaró ningúna imagen!')
: !file_exists($image)
? DIE ('¡El archivo declarado no pudo encontrarse en el servidor! ')
: false;

$imagedata = getimagesize($image);

!$imagedata[2] || $imagedata[2] == 4 || $imagedata[2] == 5
? DIE ('El archivo declarado no es una imagen ')
: false;

eval ('
if (!(imagetypes() & IMG_'.strtoupper($types[$imagedata[2]]).')) {
DIE ("lo siento;".strtoupper($types[$imagedata[2]])."- El formato no es soportado!");
}
');

!isset ($x)
? $x = floor ($y * $imagedata[0] / $imagedata[1])
: $x;

!isset ($y)
? $y = floor ($x * $imagedata[1] / $imagedata[0])
: $y;

if ($aspectratio && isset ($HTTP_GET_VARS['x']) && isset ($HTTP_GET_VARS['y'])) {
if ($imagedata[0] > $imagedata[1]) {
$y = floor ($x * $imagedata[1] / $imagedata[0]);
} else if ($imagedata[1] > $imagedata[0]) {
$x = floor ($y * $imagedata[0] / $imagedata[1]);
}
}

$thumbfile = substr ($HTTP_GET_VARS['image'], strrpos ($HTTP_GET_VARS['image'], '/') + 1);
if (file_exists ($cachedir.$thumbfile)) {
$thumbdata = getimagesize ($cachedir.$thumbfile);
$thumbdata[0] == $x && $thumbdata[1] == $y
? $iscached = true
: $iscached = false;
} else {
$iscached = false;
}

if (!$iscached) {
($imagedata[0] > $x || $imagedata[1] > $y) ||
(($imagedata[0] < $x || $imagedata[1] < $y) && $resize)
? $makethumb = true
: $makethumb = false;
} else {
$makethumb = false;
}

Header ("Content-Type: image/".$types[$imagedata[2]]);

if ($makethumb) {
$image = call_user_func("imagecreatefrom".$types[$imagedata[2]], $image);
$thumb = imagecreate ($x, $y);
imagecopyresized ($thumb, $image, 0, 0, 0, 0, $x, $y, $imagedata[0], $imagedata[1]);
call_user_func("image".$types[$imagedata[2]], $thumb, $cachedir.$thumbfile);
imagedestroy ($image);
imagedestroy ($thumb);
$image = $cachedir.$thumbfile;
} else {
$iscached
? $image = $cachedir.$thumbfile
: $image = $HTTP_GET_VARS['image'];
}
$image = fopen ($image, "rb");
fpassthru ($image);
fclose ($image);

?>