rookie7799 Posted August 18, 2006 Share Posted August 18, 2006 This is the code of rating.php file [code]<?class gd_gradient_fill { // Constructor. Creates, fills and returns an image function gd_gradient_fill($w,$h,$d,$s,$e,$step=0,$r) { $this->width = $w; $this->height = $h; $this->direction = $d; $this->startcolor = $s; $this->endcolor = $e; $this->step = intval(abs($step)); // Attempt to create a blank image in true colors, or a new palette based image if this fails if (function_exists('imagecreatetruecolor')) { $this->image = imagecreatetruecolor($this->width,$this->height); } elseif (function_exists('imagecreate')) { $this->image = imagecreate($this->width,$this->height); } else { die('Unable to create an image'); } //print " before fill "; // Fill it $this->fill($this->image,$this->direction,$this->startcolor,$this->endcolor); //print " fill "; // Show it $this->display($this->image,$r); // Return it return $this->image; } // Displays the image with a portable function that works with any file type // depending on your server software configuration function display ($im,$r) { // $colorGrey=imagecolorallocate($im, 192, 192, 192); // imageline($im, 0, 0, 0, $height, $colorGrey);// imageline($im, 0, 0, $width, 0, $colorGrey);// imageline($im, $width-1, 0, $width-1, $height-1, $colorGrey);// imageline($im, 0, $height-1, $width-1, $height-1, $colorGrey); $r = $r * 10; if ($r == 0) {$r = 1;} $im2 = imagecreatetruecolor($r,10); imagecopy($im2,$im,0,0,0,0,$r,10); if (function_exists("imagepngX")) { //header("Content-type: image/png"); //imagepng($im2,"/images/x.png"); //imagepng( } elseif (function_exists("imagegifX")) { //header("Content-type: image/gif"); //imagegif($im2); } elseif (function_exists("imagejpeg")) { header("Content-type: image/jpeg"); imagejpeg($im2, "", 100); } elseif (function_exists("imagewbmp")) { header("Content-type: image/vnd.wap.wbmp"); imagewbmp($im); } else { die("Doh ! No graphical functions on this server ?"); } return $im2; return true; } // The main function that draws the gradient function fill($im,$direction,$start,$end) { switch($direction) { case 'horizontal': $line_numbers = imagesx($im); $line_width = imagesy($im); list($r1,$g1,$b1) = $this->hex2rgb($start); list($r2,$g2,$b2) = $this->hex2rgb($end); break; case 'vertical': $line_numbers = imagesy($im); $line_width = imagesx($im); list($r1,$g1,$b1) = $this->hex2rgb($start); list($r2,$g2,$b2) = $this->hex2rgb($end); break; case 'ellipse': $width = imagesx($im); $height = imagesy($im); $rh=$height>$width?1:$width/$height; $rw=$width>$height?1:$height/$width; $line_numbers = min($width,$height); $center_x = $width/2; $center_y = $height/2; list($r1,$g1,$b1) = $this->hex2rgb($end); list($r2,$g2,$b2) = $this->hex2rgb($start); imagefill($im, 0, 0, imagecolorallocate( $im, $r1, $g1, $b1 )); break; case 'ellipse2': $width = imagesx($im); $height = imagesy($im); $rh=$height>$width?1:$width/$height; $rw=$width>$height?1:$height/$width; $line_numbers = sqrt(pow($width,2)+pow($height,2)); $center_x = $width/2; $center_y = $height/2; list($r1,$g1,$b1) = $this->hex2rgb($end); list($r2,$g2,$b2) = $this->hex2rgb($start); break; case 'circle': $width = imagesx($im); $height = imagesy($im); $line_numbers = sqrt(pow($width,2)+pow($height,2)); $center_x = $width/2; $center_y = $height/2; $rh = $rw = 1; list($r1,$g1,$b1) = $this->hex2rgb($end); list($r2,$g2,$b2) = $this->hex2rgb($start); break; case 'circle2': $width = imagesx($im); $height = imagesy($im); $line_numbers = min($width,$height); $center_x = $width/2; $center_y = $height/2; $rh = $rw = 1; list($r1,$g1,$b1) = $this->hex2rgb($end); list($r2,$g2,$b2) = $this->hex2rgb($start); imagefill($im, 0, 0, imagecolorallocate( $im, $r1, $g1, $b1 )); break; case 'square': case 'rectangle': $width = imagesx($im); $height = imagesy($im); $line_numbers = max($width,$height)/2; list($r1,$g1,$b1) = $this->hex2rgb($end); list($r2,$g2,$b2) = $this->hex2rgb($start); break; case 'diamond': list($r1,$g1,$b1) = $this->hex2rgb($end); list($r2,$g2,$b2) = $this->hex2rgb($start); $width = imagesx($im); $height = imagesy($im); $rh=$height>$width?1:$width/$height; $rw=$width>$height?1:$height/$width; $line_numbers = min($width,$height); break; default: } for ( $i = 0; $i < $line_numbers; $i=$i+1+$this->step ) { // old values : $old_r=$r; $old_g=$g; $old_b=$b; // new values : $r = ( $r2 - $r1 != 0 ) ? intval( $r1 + ( $r2 - $r1 ) * ( $i / $line_numbers ) ): $r1; $g = ( $g2 - $g1 != 0 ) ? intval( $g1 + ( $g2 - $g1 ) * ( $i / $line_numbers ) ): $g1; $b = ( $b2 - $b1 != 0 ) ? intval( $b1 + ( $b2 - $b1 ) * ( $i / $line_numbers ) ): $b1; // if new values are really new ones, allocate a new color, otherwise reuse previous color. // There's a "feature" in imagecolorallocate that makes this function // always returns '-1' after 255 colors have been allocated in an image that was created with // imagecreate (everything works fine with imagecreatetruecolor) if ( "$old_r,$old_g,$old_b" != "$r,$g,$b") $fill = imagecolorallocate( $im, $r, $g, $b ); switch($direction) { case 'vertical': imagefilledrectangle($im, 0, $i, $line_width, $i+$this->step, $fill); break; case 'horizontal': imagefilledrectangle( $im, $i, 0, $i+$this->step, $line_width, $fill ); break; case 'ellipse': case 'ellipse2': case 'circle': case 'circle2': imagefilledellipse ($im,$center_x, $center_y, ($line_numbers-$i)*$rh, ($line_numbers-$i)*$rw,$fill); break; case 'square': case 'rectangle': imagefilledrectangle ($im,$i*$width/$height,$i*$height/$width,$width-($i*$width/$height), $height-($i*$height/$width),$fill); break; case 'diamond': imagefilledpolygon($im, array ( $width/2, $i*$rw-0.5*$height, $i*$rh-0.5*$width, $height/2, $width/2,1.5*$height-$i*$rw, 1.5*$width-$i*$rh, $height/2 ), 4, $fill); break; default: } } } // #ff00ff -> array(255,0,255) or #f0f -> array(255,0,255) function hex2rgb($color) { $color = str_replace('#','',$color); $s = strlen($color) / 3; $rgb[]=hexdec(str_repeat(substr($color,0,$s),2/$s)); $rgb[]=hexdec(str_repeat(substr($color,$s,$s),2/$s)); $rgb[]=hexdec(str_repeat(substr($color,2*$s,$s),2/$s)); return $rgb; }}?>[/code]When I try to use this:[code]<img src="<? $image = new gd_gradient_fill(100,10,'horizontal','#ff0000','#00cc00',9,number_format($newArray['song_Rating'],4));?> " />[/code]it just shows this AND NO PICTURE...[code]#ИЏ яcZъ‰Ћ6,?еЇэіяЩлjЛю>bяЃяи·¬[щkяlяцzЪІяЏїаъ-лБЕьuГяёСьв§ыЧяШ¦ЇюЁйХРW?]|ю/ю]яЫяыiюuш“я2_ыЁяоЃЅeяСАяфcЦХ‡ьµя¶ы=bЩЗґ_р?эхµaя-нџюП_?‹ш*я‹яr#ьлсSэЧ‹мmWяW”Ќ‹_шшЏюя 5lV=Їь|GяяР¶+БЇсЇрЇНџА^#Иу яbЄъ—Ћ?яЩ " /> [/code]WHY ? any ideas ? Thanks Quote Link to comment Share on other sites More sharing options...
Barand Posted August 18, 2006 Share Posted August 18, 2006 Create a php file like this, called, say, 'gradient_image.php'[code]<?php// put your class code here// or include a file containing the class code$image = new gd_gradient_fill(100,10,'horizontal','#ff0000','#00cc00',9,number_format($newArray['song_Rating'],4));header ("content-type: image/png");imagepng ($image);imagedestroy ($image);?>[/code]Now you can use your image tag[code]<IMG src="gradient_image.php">[/code] Quote Link to comment Share on other sites More sharing options...
Caesar Posted August 18, 2006 Share Posted August 18, 2006 Create your image in another file. (Eg image.php) Then call up the image as so:[CODE]<?phpecho'<img src="image.php">';?>[/CODE] Quote Link to comment Share on other sites More sharing options...
rookie7799 Posted August 19, 2006 Author Share Posted August 19, 2006 The image that is being created requires parameters and I need to pass them somehow, either by putting the image creating into a function or a class... and for some reason it doesn'tt work like that Quote Link to comment Share on other sites More sharing options...
rookie7799 Posted August 19, 2006 Author Share Posted August 19, 2006 the onlu possible solution that I see is to store the image temperally on a disk... and then in the image creatiion file do something like this:[code] imagejpeg($im2, "".$imgstr.".jpeg", 100); print $myimg = $imgstr.".jpeg";[/code]and in the file you want to see that image:[code]<img src="<? $image = new gd_gradient_fill(100,10,'horizontal','#ff0000','#00cc00',9,number_format($newArray['song_Rating'],4));?> " />[/code] :-\ Quote Link to comment Share on other sites More sharing options...
rookie7799 Posted August 19, 2006 Author Share Posted August 19, 2006 [quote author=Barand link=topic=104809.msg418296#msg418296 date=1155939823]Create a php file like this, called, say, 'gradient_image.php'[code]<?php// put your class code here// or include a file containing the class code$image = new gd_gradient_fill(100,10,'horizontal','#ff0000','#00cc00',9,number_format($newArray['song_Rating'],4));header ("content-type: image/png");imagepng ($image);imagedestroy ($image);?>[/code]Now you can use your image tag[code]<IMG src="gradient_image.php">[/code][/quote]Thank you for suggestion it works with some mods :)[code]img src="image.php?rating=<?=number_format($newArray['song_Rating'],4);?>[/code]and this is the image.php file:[code]<?phprequire_once "_global.php";$image = new gd_gradient_fill(100,10,'horizontal','#ff0000','#00cc00',9,$_REQUEST['rating']);?>[/code] ;D ;) :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.