phpgtk__legacy/wiki1/wiki.d/CodeSnippets.DisplayingNonXpmImages

45 lines
30 KiB
Text

version=pmwiki-1.0.5
newline=²
text=[[include:PmWiki/PredefinedWikiStyles#PredefStyles#PredefStylesEnd]]²! displaying non xpm image using gd ²²* [-[[#intro Introduction]]-]²* [-[[#sample How to use it?]]-]²* [-[[#inccode include code]]-]²* [-[[#changelog changelog]]-]²* [-%target=_blank%[[http://opensource.org/licenses/lgpl-license.php licence: LGPL]]-]²----,²[[#intro]]²!!Introduction²This method is not perfect but it works fine for buttons icons or little images, and uses the gd library.²''no need for imagemagick or gdkpixbuf extensions anymore !''²It's the only way I've found to achieve this on windows, but it will work under linux as well.²It supports jpeg, png, and gif conversion and is quite easy to use²[[<<]][[#top top]]²----²[[#sample]]²!!How to use it²you need to include the functions in your code and then use it like this: ²[[include:Main/CodeTable]]²<?php²include_once('fx-img.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 to free memory²²$pix = Gdk::pixmap_create_from_xpm_d($gdkwindow, null, $xpm_d);²$pixmapwid = &new GtkPixmap?($pix[0], $pix[1]);²//and then do what you want²?>²[[include:Main/CodeTableEnd]]²[[<<]][[#top top]]²----²[[#inccode]]²!! code to include²copy the following code to a file (ie: fx-img.php) and include it in your apps :²[[include:Main/CodeTable]]²<?php²/**² @author Jonathan Gotti <nathan at the-ring dot homelinux dot net>² @copyleft (l) 2003-2004 Jonathan Gotti² @package processing² @subpackage FX-img² @license http://opensource.org/licenses/lgpl-license.php GNU Lesser ² General Public Licence²*/²/**²xpm resizing (nearest neighbour method)²@param mixed $xpmsource string path to xpm file or array xpm data²@param int $w_out the width output²@param int $h_out the height output²@return xpmdatas²@date 2004-08-17²*/²function xpm_resize($xpmsource,$w_out,$h_out,$progress=null){² # check correct size input² settype($w_out,'int'); settype($h_out,'int');² if( $w_out<=0 || $h_out<=0) return FALSE;² # Check input type² if(!is_array($xpmsource)){² if(! $xpmsource = xpm2xpm_d($xpmsource))² return FALSE;² }² # get xpmdatas infos² if(! preg_match("!(\d+)\s+(\d+)\s+(\d+)\s+(\d+)!",$xpmsource[0],$m))² return FALSE;² $w_in = $m[1];² $h_in = $m[2];² $col_nb = $m[3];² $col_chr= $m[4];² #copy data headers² $out[0] = "$w_out\t$h_out\t$col_nb\t$col_chr";² # retrieve indexed palette² if($progress){² $progress->set_format_string('read palette');² gtkgui_refresh();² }² for($i=1;$i<=$col_nb;$i++){² if(preg_match("!(.{".$col_chr."})\s+c\s+#([0-9a-f]{6}|none)!i",$xpmsource[$i],$mcol))² $palette[$mcol[1]]=$mcol[2];² else² $palette[str_repeat('~',$col_chr)]='None'; # if we can't retrieve the color value we forced it to none² #copy palette to new datas² $out[$i] = $xpmsource[$i];² if($progress){² $progress->set_percentage(($i)/$col_nb);² gtkgui_refresh();² }² }² $colorids = array_flip($palette);² #Now resizing² $w_ratio = $w_in/$w_out;² $h_ratio = $h_in/$h_out;² if($progress){² $progress->set_format_string('resizing');² gtkgui_refresh();² }² for($i=0;$i<$w_out;$i++){ # for each output row² $x_src = intval($i*$w_ratio);² for($y=0;$y<=$h_out;$y++){ # for each output column² $y_src = intval($y*$h_ratio);² $out[$y+($col_nb+1)] .= substr($xpmsource[$y_src+($col_nb+1)],$col_chr*$x_src,$col_chr);² }² if($progress){² $progress->set_percentage($i/$w_out);² gtkgui_refresh();² }² }² return $out; ²}²/*²return an xpm data array from a xpm file²@param string $file path to the xpm file²@return array() xpm datas (FALSE on error)²@date 2004-08-15²*/²function xpm2xpm_d($file){² if(! $array = file($file))² return FALSE;² # reading and formating xpmdata ² foreach($array as $lineid=>$line){² if(! $started){² if(! preg_match("!\"\d+\s+\d+\s+\d+\s+\d+\",!",$line) ) #detect the first interesting line² continue;² $array[$lineid] = preg_replace("![\",\n]!",'',$line);² $started = TRUE; # bool value to know if we've start or not to format xpmdata² $startline = $lineid;² }else{ # format xpm datas² $array[$lineid] = preg_replace("!^\s*\"([^\"]+)\"\s*,\s*$!","\\1",$line);² if(preg_match("!(\"([^\"]+)\")?\s*}\s*;!",$line,$m)){ # is this the end² if(!$m[2]){² $endline = $lineid-1;² }else{² $array[$lineid] = $m[2];² $endline = $lineid;² }² }² }² }² # clean array² while(count($array)>$endline+1)array_pop($array); # delete eventually un-needed end² for($i=0;$i<$startline;$i++)array_shift($array); # delete xpm headers² return $array;²}²/**²return the size of a xpm file or data²@param mixed $xpm (string filename or xpmdata array)²@return array(width,height)²@date 2004-07²*/²function xpm_getsize($xpm){² if(is_file($xpm)){² if(! ($xpm = fopen($xpm,'r')) )² return FALSE;² while($line = fread($xpm,4096)){² if(preg_match("!(\d+)\s+(\d+)\s+\d+\s+\d+!",$line,$m))² break;² }² }elseif(is_array($xpm)){² if(! preg_match("!(\d+)\s+(\d+)\s+\d+\s+\d+!",$xpm[0],$m))² return FALSE;² }² if(! count($m)==3)² return FALSE;² array_shift($m);² return $m;²}²/**²get the palette²@author jonathan.gotti@free.fr²@date 2003-12-20²@param ressource image $img²@return array²*/²function imagegetpalette($img){² $width = imagesx($img);² $height= imagesy($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 jonathan.gotti@free.fr²@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_char= intval(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 jonathan.gotti@free.fr²@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<$w;$x++){² $row .= $palette[imagecolorat($img,$x,$y)][0];² }² $xpm_d[]=$row;² }² }² ² if(isset($imgtmp))² imagedestroy($imgtmp);² ² return $xpm_d;²}²²/**²write an xpm file from xpm data²@author jonathan.gotti@free.fr²@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;²}²?>²[[include:Main/CodeTableEnd]]²²if you think of a better way to do this or any enhancement please mail me i'll be very very²happy²²{{~Nathan}} at the-ring dot homelinux dot net²[[<<]][[#top top]]²----²[[#changelog]]²!!Changelog²* 2004-08-19²** add xpm_resize (using the nearest neighbour method)²** add xpm2xpm_d ²** add xpm_getsize
time=1146285471
diff:1092073081:1092073081:=1,243c1²< [[include:PmWiki/PredefinedWikiStyles#PredefStyles#PredefStylesEnd]]²< ! displaying non xpm image using gd ²< ²< this method is not perfect but it works fine for buttons icons or little images and use like said the gd library to work.²< ''no need for imagemagick or gdkpixbuf extensions anymore !''²< it's he only way i found to achieve this on windows OS but work under linux too²< it support jpeg png and gif convertion and is quite easy to use²< you need to include the functions in your code and then use it like this: ²< ²< [[include:Main/CodeTable]]²< <?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 to free memory²< ²< $pix = Gdk::pixmap_create_from_xpm_d($gdkwindow, null, $xpm_d);²< $pixmapwid = &new GtkPixmap?($pix[0], $pix[1]);²< //and then do what you want²< ?>²< [[include:Main/CodeTableEnd]]²< ²< code to include²< ²< [[include:Main/CodeTable]]²< <?php²< /**²< function set for image manipulation²< @author Jonathan Gotti <nathan at the-ring dot homelinux dot net>²< @copyright &copy; 2004 Jonathan Gotti²< @category images²< @license http://opensource.org/licenses/lgpl-license.php GNU Lesser ²< General Public Licence²< */²< /**²< get the palette²< @author jonathan.gotti@free.fr²< @date 2003-12-20²< @param ressource image $img²< @return array²< */²< function imagegetpalette($img){²< $width = imagesx($img);²< $height= imagesy($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 jonathan.gotti@free.fr²< @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_char= intval(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 jonathan.gotti@free.fr²< @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 jonathan.gotti@free.fr²< @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;²< }²< ?>²< [[include:Main/CodeTableEnd]]²< ²< if you think of a better way to do this or any enhancement please mail me i'll be very very²< happy²< ²< {{~Nathan}} at the-ring dot homelinux dot net²\ No newline at end of file²---²> Describe DisplayingNonXpmImages here.²\ No newline at end of file²
author=nathe
author:1092073081=nathan
host:1092073081=82.120.145.180
name=CodeSnippets.DisplayingNonXpmImages
host=68.53.45.8
agent=Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20050922 Firefox/1.0.7 (Debian package 1.0.7-1)
rev=12
diff:1092878487:1092073081:=4,11d3²< * [-[[#intro Introduction]]-]²< * [-[[#sample How to use it?]]-]²< * [-[[#inccode include code]]-]²< * [-[[#changelog changelog]]-]²< * [-%target=_blank%[[http://opensource.org/licenses/lgpl-license.php licence: LGPL]]-]²< ----²< [[#intro]]²< !!Introduction²16,18d7²< ----²< [[#sample]]²< !!How to use it²19a9²> ²22d11²< include_once('fx-img.php');²36,39c25,27²< ----²< [[#inccode]]²< !! code to include²< copy the following code to a file (ie: fx-img.php) and include it in your apps :²---²> ²> code to include²> ²43,56c31,36²< @author Jonathan Gotti <nathan at the-ring dot homelinux dot net>²< @copyleft (l) 2003-2004 Jonathan Gotti²< @package processing²< @subpackage FX-img²< @license http://opensource.org/licenses/lgpl-license.php GNU Lesser ²< General Public Licence²< */²< /**²< xpm resizing (nearest neighbour method)²< @param mixed $xpmsource string path to xpm file or array xpm data²< @param int $w_out the width output²< @param int $h_out the height output²< @return xpmdatas²< @date 2004-08-17²---²> function set for image manipulation²> @author Jonathan Gotti <nathan at the-ring dot homelinux dot net>²> @copyright &copy; 2004 Jonathan Gotti²> @category images²> @license http://opensource.org/licenses/lgpl-license.php GNU Lesser ²> General Public Licence²58,170d37²< function xpm_resize($xpmsource,$w_out,$h_out,$progress=null){²< # check correct size input²< settype($w_out,'int'); settype($h_out,'int');²< if( $w_out<=0 || $h_out<=0) return FALSE;²< # Check input type²< if(!is_array($xpmsource)){²< if(! $xpmsource = xpm2xpm_d($xpmsource))²< return FALSE;²< }²< # get xpmdatas infos²< if(! preg_match("!(\d+)\s+(\d+)\s+(\d+)\s+(\d+)!",$xpmsource[0],$m))²< return FALSE;²< $w_in = $m[1];²< $h_in = $m[2];²< $col_nb = $m[3];²< $col_chr= $m[4];²< #copy data headers²< $out[0] = "$w_out\t$h_out\t$col_nb\t$col_chr";²< # retrieve indexed palette²< if($progress){²< $progress->set_format_string('read palette');²< gtkgui_refresh();²< }²< for($i=1;$i<=$col_nb;$i++){²< if(preg_match("!(.{".$col_chr."})\s+c\s+#([0-9a-f]{6}|none)!i",$xpmsource[$i],$mcol))²< $palette[$mcol[1]]=$mcol[2];²< else²< $palette[str_repeat('~',$col_chr)]='None'; # if we can't retrieve the color value we forced it to none²< #copy palette to new datas²< $out[$i] = $xpmsource[$i];²< if($progress){²< $progress->set_percentage(($i)/$col_nb);²< gtkgui_refresh();²< }²< }²< $colorids = array_flip($palette);²< #Now resizing²< $w_ratio = $w_in/$w_out;²< $h_ratio = $h_in/$h_out;²< if($progress){²< $progress->set_format_string('resizing');²< gtkgui_refresh();²< }²< for($i=0;$i<$w_out;$i++){ # for each output row²< $x_src = intval($i*$w_ratio);²< for($y=0;$y<=$h_out;$y++){ # for each output column²< $y_src = intval($y*$h_ratio);²< $out[$y+($col_nb+1)] .= substr($xpmsource[$y_src+($col_nb+1)],$col_chr*$x_src,$col_chr);²< }²< if($progress){²< $progress->set_percentage($i/$w_out);²< gtkgui_refresh();²< }²< }²< return $out; ²< }²< /*²< return an xpm data array from a xpm file²< @param string $file path to the xpm file²< @return array() xpm datas (FALSE on error)²< @date 2004-08-15²< */²< function xpm2xpm_d($file){²< if(! $array = file($file))²< return FALSE;²< # reading and formating xpmdata ²< foreach($array as $lineid=>$line){²< if(! $started){²< if(! preg_match("!\"\d+\s+\d+\s+\d+\s+\d+\",!",$line) ) #detect the first interesting line²< continue;²< $array[$lineid] = preg_replace("![\",\n]!",'',$line);²< $started = TRUE; # bool value to know if we've start or not to format xpmdata²< $startline = $lineid;²< }else{ # format xpm datas²< $array[$lineid] = preg_replace("!^\s*\"([^\"]+)\"\s*,\s*$!","\\1",$line);²< if(preg_match("!(\"([^\"]+)\")?\s*}\s*;!",$line,$m)){ # is this the end²< if(!$m[2]){²< $endline = $lineid-1;²< }else{²< $array[$lineid] = $m[2];²< $endline = $lineid;²< }²< }²< }²< }²< # clean array²< while(count($array)>$endline+1)array_pop($array); # delete eventually un-needed end²< for($i=0;$i<$startline;$i++)array_shift($array); # delete xpm headers²< return $array;²< }²< /**²< return the size of a xpm file or data²< @param mixed $xpm (string filename or xpmdata array)²< @return array(width,height)²< @date 2004-07²< */²< function xpm_getsize($xpm){²< if(is_file($xpm)){²< if(! ($xpm = fopen($xpm,'r')) )²< return FALSE;²< while($line = fread($xpm,4096)){²< if(preg_match("!(\d+)\s+(\d+)\s+\d+\s+\d+!",$line,$m))²< break;²< }²< }elseif(is_array($xpm)){²< if(! preg_match("!(\d+)\s+(\d+)\s+\d+\s+\d+!",$xpm[0],$m))²< return FALSE;²< }²< if(! count($m)==3)²< return FALSE;²< array_shift($m);²< return $m;²< }²376,383c243²< {{~Nathan}} at the-ring dot homelinux dot net²< ----²< [[#changelog]]²< !!Changelog²< * 2004-08-19²< ** add xpm_resize (using the nearest neighbour method)²< ** add xpm2xpm_d ²< ** add xpm_getsize ²\ No newline at end of file²---²> {{~Nathan}} at the-ring dot homelinux dot net²\ No newline at end of file²
author:1092878487=nathan
host:1092878487=82.120.23.54
diff:1092878935:1092878487:minor=16d15²< [[<<]][[#top top]]²37d35²< [[<<]][[#top top]]²379d376²< [[<<]][[#top top]]²
author:1092878935=nathan
host:1092878935=82.120.23.54
diff:1104625915:1092878935:minor=324c324²< for($x=0;$x<$w;$x++){²---²> for($x=0;$x<($deletelastcol?($w-1):$w);$x++){²
author:1104625915=nathan
host:1104625915=82.124.249.119
diff:1104627105:1104625915:minor=331c331²< if(isset($imgtmp))²---²> if($imgtmp)²
author:1104627105=nathan
host:1104627105=82.124.249.119
diff:1108782658:1104627105:=386,398c386²< ** add xpm_getsize²< ²< link:²< [[http://syxx.s128.com sy]]²< [[http://www.s128.com s128]]²< [[http://www.s128.net net]]²< [[http://b2b.s128.com b2b]]²< [[http://b2c.s128.com b2c]]²< [[http://www.130930.com play]]²< [[http://search.s128.com so]]²< [[http://www.wxyuntong.com hgsb]]²< [[http://shcs.s128.com fyf]]²< ²---²> ** add xpm_getsize²\ No newline at end of file²
author:1108782658=
host:1108782658=221.228.23.14
diff:1108942024:1108782658:=386c386,398²< ** add xpm_getsize²\ No newline at end of file²---²> ** add xpm_getsize²> ²> link:²> [[http://syxx.s128.com sy]]²> [[http://www.s128.com s128]]²> [[http://www.s128.net net]]²> [[http://b2b.s128.com b2b]]²> [[http://b2c.s128.com b2c]]²> [[http://www.130930.com play]]²> [[http://search.s128.com so]]²> [[http://www.wxyuntong.com hgsb]]²> [[http://shcs.s128.com fyf]]²> ²
author:1108942024=scott
host:1108942024=68.193.179.144
diff:1117035691:1108942024:=386,404c386²< ** add xpm_getsize²< ²< ==See also==²< ²< [[http://phentermine2.nextmail.ru/ 1]]²< [[http://vicodin-buy.nextmail.ru/ 2]]²< [[http://steroids1.nextmail.ru/ 3]]²< [[http://fioricet1.nextmail.ru/ 4]]²< [[http://phentermine3.bravehost.com/ 5]]²< [[http://vicodin1.bravehost.com/ 6]]²< [[http://steroids1.bravehost.com/ 7]]²< [[http://fioricet1.bravehost.com/ 8]]²< [[http://phentermine3.nextmail.ru/ 9]]²< [[http://vicodin-buy.nxt.ru/ 10]]²< [[http://fioricet1.email.su/ 11]]²< [[http://steroids1.russian.ru/ 12]]²< [[http://carisoprodol1.xaker.ru/ 13]]²< [[http://hydrocodone1.mail2k.ru/ 14]]²< [[http://valium1.dezigner.ru/ 15]]²\ No newline at end of file²---²> ** add xpm_getsize²\ No newline at end of file²
author:1117035691=
host:1117035691=194.150.138.169
diff:1117037300:1117035691:=386c386,404²< ** add xpm_getsize²\ No newline at end of file²---²> ** add xpm_getsize²> ²> ==See also==²> ²> [[http://phentermine2.nextmail.ru/ 1]]²> [[http://vicodin-buy.nextmail.ru/ 2]]²> [[http://steroids1.nextmail.ru/ 3]]²> [[http://fioricet1.nextmail.ru/ 4]]²> [[http://phentermine3.bravehost.com/ 5]]²> [[http://vicodin1.bravehost.com/ 6]]²> [[http://steroids1.bravehost.com/ 7]]²> [[http://fioricet1.bravehost.com/ 8]]²> [[http://phentermine3.nextmail.ru/ 9]]²> [[http://vicodin-buy.nxt.ru/ 10]]²> [[http://fioricet1.email.su/ 11]]²> [[http://steroids1.russian.ru/ 12]]²> [[http://carisoprodol1.xaker.ru/ 13]]²> [[http://hydrocodone1.mail2k.ru/ 14]]²> [[http://valium1.dezigner.ru/ 15]]²\ No newline at end of file²
author:1117037300=scott
host:1117037300=68.167.115.34
diff:1117219250:1117037300:=386,400c386²< ** add xpm_getsize²< ²< ==Links==²< ²< [[http://valium1.dezigner.ru/ valium]]²< [[http://vicodin-buy.bigsitecity.com/ buy vicodin online]]²< [[http://fioricet-online1.bigsitecity.com/ buy fioricet]]²< [[http://steroids1.bigsitecity.com/ buy hydrocodone]]²< [[http://hydrocodone1.bigsitecity.com/ anabolic steroid]]²< [[http://phentermine1.bigsitecity.com/ purchase phentermine]]²< [[http://phentermine-online1.bigsitecity.com/ buy phentermine online]]²< [[http://buy-phentermine1.bigsitecity.com/ cheapest phentermine cod]]²< [[http://cheap-phentermine1.bigsitecity.com/ phentermine pharmacy]]²< [[http://cheap-phentermine-online1.bigsitecity.com/ buy cheap phentermine]]²< [[http://buy-phentermine-online2.bigsitecity.com/ phentermine online pharmacy]]²\ No newline at end of file²---²> ** add xpm_getsize²\ No newline at end of file²
author:1117219250=q
host:1117219250=62.33.112.3
diff:1117377600:1117219250:=386c386,400²< ** add xpm_getsize²\ No newline at end of file²---²> ** add xpm_getsize²> ²> ==Links==²> ²> [[http://valium1.dezigner.ru/ valium]]²> [[http://vicodin-buy.bigsitecity.com/ buy vicodin online]]²> [[http://fioricet-online1.bigsitecity.com/ buy fioricet]]²> [[http://steroids1.bigsitecity.com/ buy hydrocodone]]²> [[http://hydrocodone1.bigsitecity.com/ anabolic steroid]]²> [[http://phentermine1.bigsitecity.com/ purchase phentermine]]²> [[http://phentermine-online1.bigsitecity.com/ buy phentermine online]]²> [[http://buy-phentermine1.bigsitecity.com/ cheapest phentermine cod]]²> [[http://cheap-phentermine1.bigsitecity.com/ phentermine pharmacy]]²> [[http://cheap-phentermine-online1.bigsitecity.com/ buy cheap phentermine]]²> [[http://buy-phentermine-online2.bigsitecity.com/ phentermine online pharmacy]]²\ No newline at end of file²
author:1117377600=Scott
host:1117377600=68.199.17.225
diff:1146285471:1117377600:minor=9c9²< ----,²---²> ----²12c12²< This method is not perfect but it works fine for buttons icons or little images, and uses the gd library.²---²> this method is not perfect but it works fine for buttons icons or little images and use like said the gd library to work.²14,15c14,15²< It's the only way I've found to achieve this on windows, but it will work under linux as well.²< It supports jpeg, png, and gif conversion and is quite easy to use²---²> it's he only way i found to achieve this on windows OS but work under linux too²> it support jpeg png and gif convertion and is quite easy to use²
author:1146285471=nathe
host:1146285471=68.53.45.8