Ver Mensaje Individual
  #2 (permalink)  
Antiguo 05/03/2011, 08:39
maurosarria
 
Fecha de Ingreso: noviembre-2010
Mensajes: 8
Antigüedad: 14 años
Puntos: 0
Respuesta: codigo me cambie el color de imagen a paleta

}
####################### IMAGE Functions #######################
function resize_pict($filename, $dest, $width, $height, $pictype = ""){
if ($pictype == "thumb") resize_pict_1($filename, $dest, $width, $height, $pictype = "");
else resize_pict_2($filename, $dest, $width, $height, $pictype = "");
return true;
}
function resize_pict_1($filename, $dest, $width, $height, $pictype = ""){
@unlink ($dest);
$format=strtolower(substr(strrchr($filename, "."), 1));

switch ($format) {
case 'gif':
$type="gif";
$img = imagecreatefromgif($filename);
$img = makeGifTrueColor($img);
break;
case 'tmp':
$type="jpg";
$img = imagecreatefromjpeg($filename);
break;
case 'png':
$type="png";
$img = imagecreatefrompng($filename);
break;
case 'jpg':
$type="jpg";
$img = imagecreatefromjpeg($filename);
break;
case 'jpeg':
$type="jpg";
$img = imagecreatefromjpeg($filename);
break;
default:
$type="jpg";
$img = imagecreatefromjpeg($filename);
break;
// die ("ERROR; UNSUPPORTED IMAGE TYPE");
// break;
}
list($org_width, $org_height) = getimagesize($filename);
$xoffset = 0;
$yoffset = 0;
if ($org_width < $width && $org_height < $height){
$width = $org_width;
$height = $org_height;
}
if ($pictype == "thumb") {
if ($org_width / $width > $org_height / $height) {
$xtmp =$org_width;
$xratio =1 - ((($org_width / $org_height) - ($width / $height)) / 2);
$org_width=$org_width * $xratio;
$xoffset =($xtmp - $org_width) / 2;
}
elseif ($org_height / $height > $org_width / $width) {
$ytmp =$org_height;
$yratio =1 - ((($width / $height) - ($org_width / $org_height)) / 2);
$org_height=$org_height * $yratio;
$yoffset =($ytmp - $org_height) / 2;
}
}
$img_n = imagecreatetruecolor($width, $height);
imagecopyresampled($img_n, $img, 0, 0, $xoffset, $yoffset, $width, $height, $org_width, $org_height);
if ($width > $org_width || $height > $org_height ) imagejpeg($img, $dest);
else imagejpeg($img_n, $dest);
return true;
}
function resize_pict_2($filename, $dest, $twidth, $theight, $pictype = ""){
@unlink ($dest);
$format=strtolower(substr(strrchr($filename, "."), 1));

switch ($format) {
case 'gif':
$type="gif";
$simg = imagecreatefromgif($filename);
$simg = makeGifTrueColor($simg);
break;
case 'tmp':
$type="jpg";
$simg = imagecreatefromjpeg($filename);
break;
case 'png':
$type="png";
$simg = imagecreatefrompng($filename);
break;
case 'jpg':
$type="jpg";
$simg = imagecreatefromjpeg($filename);
break;
case 'jpeg':
$type="jpg";
$simg = imagecreatefromjpeg($filename);
break;
default:
$type="jpg";
$simg = imagecreatefromjpeg($filename);
break;
// die ("ERROR; UNSUPPORTED IMAGE TYPE");
// break;
}
$currwidth = imagesx($simg);
$currheight = imagesy($simg);
if ($currwidth < $twidth && $currheight < $theight){
$twidth = $currwidth;
$theight = $currheight;
}
if ($currheight > $currwidth) {
$zoom = $twidth / $currheight;
$newheight = $theight;
$newwidth = $currwidth * $zoom;
} else {
$zoom = $twidth / $currwidth;
$newwidth = $twidth;
$newheight = $currheight * $zoom;
}
$dimg = imagecreate($newwidth, $newheight);
imagetruecolortopalette($simg, false, 256);
$palsize = ImageColorsTotal($simg);
for ($i = 0; $i < $palsize; $i++) {
$colors = ImageColorsForIndex($simg, $i);
ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']);
}
imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);
imagejpeg($dimg, $dest);
imagedestroy($simg);
imagedestroy($dimg);
return true;
}
function makeGifTrueColor($img){
if (!imageistruecolor($img)) {
$w = imagesx($img);
$h = imagesy($img);
$original_transparency = imagecolortransparent($img);
if ($original_transparency >= 0) {
$background = @imagecreate($w, $h);
imagecolorallocate($background, 255, 255, 255);
imagecopymerge($background,$img,0,0,0,0,$w,$h,100) ;
$img = $background;
}
}
return $img;
}



asi lo tengo completo

ayuda por favor necesito que me salga el color verdadero de las imagenes

Última edición por maurosarria; 05/03/2011 a las 10:01