Jump to content


Photo

Unable to view image inside the table tag


  • Please log in to reply
5 replies to this topic

#1 rookie7799

rookie7799
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 18 August 2006 - 10:09 PM

This is the code of rating.php file

<?
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;
	}
}
?>


When I try to use this:
<img src="
<?		$image = new gd_gradient_fill(100,10,'horizontal','#ff0000','#00cc00',9,number_format($newArray['song_Rating'],4));
?>		" />
it just shows this AND NO PICTURE...
#ИЏ яcZъ‰Ћ6,?еЇэіяЩлjЛю>bяЃяи·¬[щkяlяцzЪІяЏ˜їаъ-лБЕьuГяёСьв§ыЧяШ¦ЇюЁйХРW?]|ю/ю]яЫяыiюuш“я2_ыЁяоЃЅeяСАяфcЦХ‡ьµя¶ы=bЩЗґ_р?эхµaя-нџюП_?‹ш*я‹яr#ьлсSэЧ‹мmWяW”Ќ‹_шшЏюя 5lV=Їь|GяяР¶+БЇсЇрЇНџА^#Иу яbЄъ—Ћ?яЩ " />
WHY ? any ideas ? Thanks


#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,023 posts

Posted 18 August 2006 - 10:23 PM

Create a php file like this, called, say,  'gradient_image.php'

<?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);
?>

Now you can use your image tag

<IMG src="gradient_image.php">

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 18 August 2006 - 10:25 PM

Create your image in another file. (Eg image.php) Then call up the image as so:

<?php
echo'
<img src="image.php">
';
?>

PHP Ninja

#4 rookie7799

rookie7799
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 19 August 2006 - 06:55 AM

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

#5 rookie7799

rookie7799
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 19 August 2006 - 07:21 AM

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:
imagejpeg($im2, "".$imgstr.".jpeg", 100);
			print $myimg = $imgstr.".jpeg";

and in the file you want to see that image:
<img src="
<?		$image = new gd_gradient_fill(100,10,'horizontal','#ff0000','#00cc00',9,number_format($newArray['song_Rating'],4));
?>		" />
:-\

#6 rookie7799

rookie7799
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 19 August 2006 - 08:36 AM

Create a php file like this, called, say,  'gradient_image.php'

<?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);
?>

Now you can use your image tag

<IMG src="gradient_image.php">


Thank you for suggestion it works with some mods :)
img src="image.php?rating=<?=number_format($newArray['song_Rating'],4);?>

and this is the image.php file:
<?php
require_once "_global.php";
$image = new gd_gradient_fill(100,10,'horizontal','#ff0000','#00cc00',9,$_REQUEST['rating']);
?>
;D ;) :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users