16/02/2008, 23:48
|
| | | Fecha de Ingreso: junio-2006
Mensajes: 550
Antigüedad: 18 años, 7 meses Puntos: 7 | |
Re: Subir Imagen Continuación class.upload.php
Código:
// we now do all the image manipulations
$this->log .= '- image resizing or conversion wanted<br />';
if ($this->gdversion()) {
switch($this->image_src_type) {
case 'jpg':
if (!function_exists('imagecreatefromjpeg')) {
$this->processed = false;
$this->error = $this->translate('no_create_support', array('JPEG'));
} else {
$image_src = @imagecreatefromjpeg($this->file_src_pathname);
if (!$image_src) {
$this->processed = false;
$this->error = $this->translate('create_error', array('JPEG'));
} else {
$this->log .= '- source image is JPEG<br />';
}
}
break;
case 'png':
if (!function_exists('imagecreatefrompng')) {
$this->processed = false;
$this->error = $this->translate('no_create_support', array('PNG'));
} else {
$image_src = @imagecreatefrompng($this->file_src_pathname);
if (!$image_src) {
$this->processed = false;
$this->error = $this->translate('create_error', array('PNG'));
} else {
$this->log .= '- source image is PNG<br />';
}
}
break;
case 'gif':
if (!function_exists('imagecreatefromgif')) {
$this->processed = false;
$this->error = $this->translate('no_create_support', array('GIF'));
} else {
$image_src = @imagecreatefromgif($this->file_src_pathname);
if (!$image_src) {
$this->processed = false;
$this->error = $this->translate('create_error', array('GIF'));
} else {
$this->log .= '- source image is GIF<br />';
}
}
break;
case 'bmp':
if (!method_exists($this, 'imagecreatefrombmp')) {
$this->processed = false;
$this->error = $this->translate('no_create_support', array('BMP'));
} else {
$image_src = @$this->imagecreatefrombmp($this->file_src_pathname);
if (!$image_src) {
$this->processed = false;
$this->error = $this->translate('create_error', array('BMP'));
} else {
$this->log .= '- source image is BMP<br />';
}
}
break;
default:
$this->processed = false;
$this->error = $this->translate('source_invalid');
}
} else {
$this->processed = false;
$this->error = $this->translate('gd_missing');
}
if ($this->processed && $image_src) {
// we have to set image_convert if it is not already
if (empty($this->image_convert)) {
$this->log .= '- setting destination file type to ' . $this->file_src_name_ext . '<br />';
$this->image_convert = $this->file_src_name_ext;
}
if (!in_array($this->image_convert, $this->image_supported)) {
$this->image_convert = 'jpg';
}
// we set the default color to be the background color if we don't output in a transparent format
if ($this->image_convert != 'png' && $this->image_convert != 'gif' && !empty($this->image_default_color) && empty($this->image_background_color)) $this->image_background_color = $this->image_default_color;
if (!empty($this->image_background_color)) $this->image_default_color = $this->image_background_color;
if (empty($this->image_default_color)) $this->image_default_color = '#FFFFFF';
$this->image_src_x = imagesx($image_src);
$this->image_src_y = imagesy($image_src);
$this->image_dst_x = $this->image_src_x;
$this->image_dst_y = $this->image_src_y;
$gd_version = $this->gdversion();
$ratio_crop = null;
if (!imageistruecolor($image_src)) { // $this->image_src_type == 'gif'
$this->log .= '- image is detected as having a palette<br />';
$this->image_is_palette = true;
$this->image_transparent_color = imagecolortransparent($image_src);
if ($this->image_transparent_color >= 0 && imagecolorstotal($image_src) > $this->image_transparent_color) {
$this->image_is_transparent = true;
//$this->image_transparent_color = imagecolorsforindex($image_src, $this->image_transparent_color);
$this->log .= ' palette image is detected as transparent<br />';
}
// if the image has a palette (GIF), we convert it to true color, preserving transparency
$this->log .= ' convert palette image to true color<br />';
$transparent_color = imagecolortransparent($image_src);
if ($transparent_color >= 0 && imagecolorstotal($image_src) > $transparent_color) {
$rgb = imagecolorsforindex($image_src, $transparent_color);
$transparent_color = ($rgb['red'] << 16) | ($rgb['green'] << 8) | $rgb['blue'];
imagecolortransparent($image_src, imagecolorallocate($image_src, 0, 0, 0));
}
$true_color = imagecreatetruecolor($this->image_src_x, $this->image_src_y);
imagealphablending($image_src, false);
imagesavealpha($image_src, true);
imagecopy($true_color, $image_src, 0, 0, 0, 0, $this->image_src_x, $this->image_src_y);
$image_src = $this->imagetransfer($true_color, $image_src);
if ($transparent_color >= 0) {
$this->log .= ' preserve transparency<br />';
imagealphablending($image_src, false);
imagesavealpha($image_src, true);
for ($x = 0; $x < $this->image_src_x; $x++) {
for ($y = 0; $y < $this->image_src_y; $y++) {
if (imagecolorat($image_src, $x, $y) == $transparent_color) imagesetpixel($image_src, $x, $y, 127 << 24);
}
}
}
$this->image_is_palette = false;
}
|