Ver Mensaje Individual
  #6 (permalink)  
Antiguo 18/02/2004, 14:00
Avatar de epplestun
epplestun
 
Fecha de Ingreso: octubre-2001
Mensajes: 1.621
Antigüedad: 23 años, 6 meses
Puntos: 5
buenas payo22, no tiene que ser por comando jeje puedes hacer la imagen .gif a .xpm con PHP, lo que tienes es que generar el algoritmo para generar ese .xpm

Jeje pero tranquilo que no hay que reinventar la rueda hace unas semanas estube hablando con un colega en la lista de desarrollo de PHP-GTK sobre este mismo problema y me paso un codigo que hizo el, aqui te lo dejo para que lo veas

Esta es la libreria
Código PHP:
<?php
/**
* function set for image manipulation
* @author Jonathan Gotti <[email protected]>
* @copyright &copy; 2004  Jonathan Gotti
* @category images
* @license [url]http://opensource.org/licenses/lgpl-license.php[/url] GNU Lesser 
General Public Licence
*/
/**
* get the palette
* @author [email][email protected][/email]
* @date 2003-12-20
* @param ressource image $img
* @return array
*/
function imagegetpalette($img){
 
$width imagesx($img);
 
$heightimagesy($img);
 for(
$i=0;$i<imagecolorstotal($img);$i++){
   
$colors[$i]=imagecolorsforindex($img,$i);
 }
 return 
$colors;
}
/**
* get a xpm style palette from a gd one
* @author [email][email protected][/email]
* @date 2003-12-20
* @param array $gdpalette
* @param string $indexed_type 'gd' keep the gd_index,'xpm' indexed by
xpm char code
* @param string $value_type 'char_code' the xpm char code index, 'color'
the xpm color value,'both' associated value is are array containing xpm
char code and xpm color value
*@param array $trans array of transparent color values
* @return array
*/
function gd2xpmpalette($gdpalette,$indexed_type='xpm',$value_type='color'){
 
$nb_colors count($gdpalette);
 
//initialize char array if needed
 
if($indexed_type=='xpm' || $value_type != 'color'){
   
$first_char 48;//lowest used ASCII char code
   
$last_char  126;//highest used ASCII char code
   //Thanks to my friend RHONONO for the next line
   
$nb_charintval(log($nb_colors)/log($last_char-$first_char)) +1;
   for(
$i=0;$i<=$nb_char;$i++){//initialize array of char
     
$chars[$i]=$first_char;
   }
 }

 foreach(
$gdpalette as $gdindex => $gdcolor){
   
//recompose xpm character coding only if needed
   
if($indexed_type=='xpm' || $value_type!='color'){
     
$char_code null;//initialise char_code
     
for($i=0;$i<$nb_char;$i++){//increment other chars
       
$chars[0]++;//increment chars
       
if($chars[$i]>$last_char){//check chars are in the good range
         
$chars[$i]=$first_char;
         
$chars[$i+1]++;
       }
       
$char_code chr($chars[$i]) . $char_code ;
     }
   }

   if(
$indexed_type == 'xpm')//choose indexed type
     
$outindex $char_code;
   else
//assume gd indexed wanted
     
$outindex $gdindex;

   
//the val according to it
   
switch($value_type){
     case 
'color':
       if(
$gdcolor['alpha']>=127)//keep transparent on palette image
         
$out[$outindex] = 'None';
       else
         
$out[$outindex] = strtoupper('#'.
                           
zero_fill(dechex($gdcolor['red']),2).
                           
zero_fill(dechex($gdcolor['green']),2).
                           
zero_fill(dechex($gdcolor['blue']),2));
       break;
     case 
'char_code':
       
$out[$outindex] = $char_code;
       break;
     case 
'both':
       if(
$gdcolor['alpha']>=127)//keep transparent on palette image
         
$out[$outindex] = array(0=>$char_code,1=>'None');
       else
         
$out[$outindex] = array( 0=>$char_code,
               
1=>strtoupper('#'.zero_fill(dechex($gdcolor['red']),2).
                           
zero_fill(dechex($gdcolor['green']),2).
                           
zero_fill(dechex($gdcolor['blue']),2)));
       break;
   }
 }
 return 
$out;
}

/**
* get xpm_data from gd image resource
* @author [email][email protected][/email]
* @date 2003-12-20
* @param resource gd image $img
* @return xpm data
*/
function image2xpm_d($img,$trans=TRUE){
 
$w imagesx($img);
 
$h imagesy($img);
 
//the first case is only for PNG with indexed palette
 
if(imageistruecolor($img) && $trans){
   
//create an indexed palette copy of $img
   //after various test best results are the 3 next lines
   //could be fine to have a better way
   
$imgtmp imagecreatetruecolor($w,$h);
   
imagecopymerge($imgtmp,$img,0,0,0,0,$w,$h,100);
   
imagetruecolortopalette($imgtmp,TRUE,255);//keep an index for trans

   //set the trans color to a known one
   
$transindex imagecolorallocate($imgtmp,1,1,1);
   
$transindex imagecolortransparent($imgtmp,$transindex);

   
//get all palette information needed
   
$gdpalette  imagegetpalette($imgtmp);
   
$palette    gd2xpmpalette($gdpalette,'gd','both');

   
//image definition
   
list($color0k,$color0v )= each($palette);
   
$xpm_d[0]= "$w $h ".count($palette)." ".strlen($color0v[0]);

   foreach(
$palette as $color){//recompose palette_data to xpm
     
$xpm_d[]=$color[0]." c ".$color[1];
   }

   for(
$y=0;$y<$h;$y++){//recompose image
     
$row null;
     for(
$x=0;$x<$w;$x++){
   
//obtain transparency from the original image
       
$color imagecolorsforindex($img,imagecolorat($img,$x,$y));
       
$index imagecolorat($imgtmp,$x,$y);
       if(
$color['alpha']>126)
         
$row .= $palette[$transindex][0];
       else
         
$row .= $palette[$index][0];

     }
     
$xpm_d[]=$row;
   }
 }else{
//non true color png will use this case
   
if(imageistruecolor($img))
     
imagetruecolortopalette($img,TRUE,255);

   
$gdpalette imagegetpalette($img);
   
$palette gd2xpmpalette($gdpalette,'gd','both');

   list(
$color0k,$color0v )= each($palette);
   
$xpm_d[0]= "$w $h ".count($palette)." ".strlen($color0v[0]);

   foreach(
$palette as $color){//recompose palette_data
     
$xpm_d[]=$color[0]." c ".$color[1];
   }

   for(
$y=0;$y<$h;$y++){//recompose image
     
$row null;
     for(
$x=0;$x<($deletelastcol?($w-1):$w);$x++){
       
$row .= $palette[imagecolorat($img,$x,$y)][0];
     }
     
$xpm_d[]=$row;
   }
 }

 if(
$imgtmp)
   
imagedestroy($imgtmp);

 return 
$xpm_d;
}

/**
* write an xpm file from xpm data
* @author [email][email protected][/email]
* @date 2003-12-20
* @param resource gd image $img
* @return xpm data
*/
function xpm_d2file($xpm_d,$file){
 if(! 
$f = @fopen($file,'w'))
   return 
FALSE;
 
fputs($f,"/* XPM */\nstatic char * ".basename($file)."[] = {\n");
 foreach(
$xpm_d as $k => $row){
   
fputs($f,"\"$row\",");
     
fputs($f,"\n");
 }
 
$pos ftell($f);
 
fputs($f,"};");
 
fclose($f);
 return 
TRUE;
}

/**
* left_fill with zero
* @param int|str $val to zerofill
* @param int $nbchar
* @return str
*/
function zero_fill($val,$nbchar=3){
 
settype($val,'string');
 
$len strlen($val);
 for(
$i=0;$i<($nbchar-$len);$i++){
   
$val "0$val";
 }
 return 
$val;
}
?>
Y esto su forma de uso:
Código PHP:
<?php
$file 
=  "path to your image file a gif for this example";
 if(! 
$img imagecreatefromgif($file))
   echo 
"can't load the image $file\n";
 
$xpm_d image2xpm_d($img);//there's a file convertion function too
 
imagedestroy($img);//don't forget this one
 
$pix Gdk::pixmap_create_from_xpm_d($gdkwindownull$xpm_d);
 
$pixmapwid = &new GtkPixmap($pix[0], $pix[1]);
 
//and then do what you want and be happy
?>
Espero que te sea de ayuda
__________________
Usuario registrado de Linux #288725