473,394 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Showing createimage() as undefined function.

Raju B
11
Hi all
i had written code for displaying graph.but it showing error like this:

Fatal error: Call to undefined function imagecreate() in /var/www/graph.php on line 27

what i have to do for get graph properly.
My code is:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     # ------- The graph values in the form of associative array
  3.     $values=array(
  4.         "Jan" => 110,
  5.         "Feb" => 130,
  6.         "Mar" => 215,
  7.         "Apr" => 81,
  8.         "May" => 310,
  9.         "Jun" => 110,
  10.         "Jul" => 190,
  11.         "Aug" => 175,
  12.         "Sep" => 390,
  13.         "Oct" => 286,
  14.         "Nov" => 150,
  15.         "Dec" => 196
  16.     );
  17.  
  18.  
  19.     $img_width=450;
  20.     $img_height=300; 
  21.     $margins=20;
  22.  
  23.  
  24.     # ---- Find the size of graph by substracting the size of borders
  25.     $graph_width=$img_width - $margins * 2;
  26.     $graph_height=$img_height - $margins * 2; 
  27.     $img=imagecreate($img_width,$img_height);
  28.  
  29.  
  30.     $bar_width=20;
  31.     $total_bars=count($values);
  32.     $gap= ($graph_width- $total_bars * $bar_width ) / ($total_bars +1);
  33.  
  34.  
  35.     # -------  Define Colors ----------------
  36.     $bar_color=imagecolorallocate($img,0,64,128);
  37.     $background_color=imagecolorallocate($img,43,43,43);
  38.     $border_color=imagecolorallocate($img,200,200,200);
  39.     $line_color=imagecolorallocate($img,220,220,220);
  40.  
  41.     # ------ Create the border around the graph ------
  42.  
  43.     imagefilledrectangle($img,1,1,$img_width-2,$img_height-2,$border_color);
  44.     imagefilledrectangle($img,$margins,$margins,$img_width-1-$margins,$img_height-1-$margins,$background_color);
  45.  
  46.  
  47.     # ------- Max value is required to adjust the scale    -------
  48.     $max_value=max($values);
  49.     $ratio= $graph_height/$max_value;
  50.  
  51.  
  52.     # -------- Create scale and draw horizontal lines  --------
  53.     $horizontal_lines=20;
  54.     $horizontal_gap=$graph_height/$horizontal_lines;
  55.  
  56.     for($i=1;$i<=$horizontal_lines;$i++){
  57.         $y=$img_height - $margins - $horizontal_gap * $i ;
  58.         imageline($img,$margins,$y,$img_width-$margins,$y,$line_color);
  59.         $v=intval($horizontal_gap * $i /$ratio);
  60.         imagestring($img,0,5,$y-5,$v,$bar_color);
  61.  
  62.     }
  63.  
  64.  
  65.     # ----------- Draw the bars here ------
  66.     for($i=0;$i< $total_bars; $i++){ 
  67.         # ------ Extract key and value pair from the current pointer position
  68.         list($key,$value)=each($values); 
  69.         $x1= $margins + $gap + $i * ($gap+$bar_width) ;
  70.         $x2= $x1 + $bar_width; 
  71.         $y1=$margins +$graph_height- intval($value * $ratio) ;
  72.         $y2=$img_height-$margins;
  73.         imagestring($img,0,$x1+3,$y1-10,$value,$bar_color);
  74.         imagestring($img,0,$x1+3,$img_height-15,$key,$bar_color);        
  75.         imagefilledrectangle($img,$x1,$y1,$x2,$y2,$bar_color);
  76.     }
  77.     header("Content-type:image/png");
  78.     imagepng($img);
  79.  
  80. ?>
  81.  
  82.  
Oct 13 '10 #1

✓ answered by Markus

You need the GD[1] extension to use that function.

[1] http://www.php.net/manual/en/image.installation.php

2 1981
Markus
6,050 Expert 4TB
You need the GD[1] extension to use that function.

[1] http://www.php.net/manual/en/image.installation.php
Oct 13 '10 #2
Raju B
11
thank you markus.
Now problem is solved.
Oct 13 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Randell D. | last post by:
Folks, I feel like pulling my hair out - I tried unsuccessfully over the past few days to install ImagMagick but because of version conflicts and missing libraries I had to give up. I originally...
6
by: obi wan kenobi | last post by:
i've used the Amazon PHP api for several months now to pull amazon data into my affiliate site - but recently i'm starting to get "call to undefined function" errors " Fatal error: Call to...
4
by: xcomm | last post by:
I tried to create some images with php and gd and get always Call to undefined function imagejpeg() or Call to undefined function imagepng() PHP was build with --with-gd --with-zlib but I...
3
by: Musashi | last post by:
I'm trying to access a Cloudscape/Derby database via PHP and am using the IBM DB2 Lite client which I have installed. As soon as I call db2_connect(...) in the php code, I get a db2_connect...
8
by: Cruella DeVille | last post by:
I'm writing a class to handle reading/writing from/to files like this (shortened) lass FileIO{ private $filename; private $mode; private $filePointer; private $dictionary; public function...
2
by: McHenry | last post by:
I am trying to use curl however am not having any success with a CLI script. Fatal error: Call to undefined function: curl_init() in C:\PHP4\cli\processweb.php on line 65 Windows XP PHP...
9
by: java | last post by:
Hey there, I just removed an elderly PHP4-Installation from my Windows-Box and installed PHP 5.2.1. I used the PHP4-Module as local batchfile- interpreter by E:\ersDHCP>php ./extractLog.php ...
2
by: sanjeevvs | last post by:
Call to undefined function: mysqli_connect() , i m using php5 with phpmyadmin. i am comfortabley working with mysqli in localhost.but when i launch on web it is showing above error. can...
4
by: Subash Biswas | last post by:
I keep getting Call to undefined function socket_create(); (Win XPpro on domain) IIS 6.0 PHP 5.2.5 have all extensions loaded; (and also tried enabling line extension=php_sockets.dll in php.ini)...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.