Lots of CPU usage when...

Soldato
Joined
16 Oct 2007
Posts
7,480
Location
UK
creating a very simple image using php/gd?

i have a script that counts records in a database, and then outputs as an image

but if is to be shown on every page on a website, is this going to put a huge strain on the CPU?
 
Code:
<?php 
include("jobs_config.php"); 
mysql_connect($DBHost,$DBUser,$DBPass);  
mysql_select_db($DBName);  
$strQuery=" 
    SELECT count(".$DBprefix."ext_postings.id) as totaljobs, count( DISTINCT ".$DBprefix."ext_postings.employer) as totalemployers FROM ".$DBprefix."ext_employers , ".$DBprefix."ext_postings 
    WHERE  
    ".$DBprefix."ext_postings.employer =  ".$DBprefix."ext_employers.username 
    AND expires>".time()." AND ".$DBprefix."ext_postings.active='YES'"; 
$result=mysql_query($strQuery); 
$row=mysql_fetch_assoc($result); 
$image_text = $row['totaljobs']." jobs from  ".$row['totalemployers']." companies"; 
Header ("Content-type: image/png");  
$img_handle = imageCreateFromPNG("images/toptrans2.PNG"); 
$color = ImageColorAllocate ($img_handle, 100, 100, 100); 
ImageString ($img_handle, 3, 10, 9, $image_text, $color);  
ImagePng ($img_handle);  
ImageDestroy ($img_handle);  
?>



If you wouldn't mind mate!
I really have no idea about php, have just pieced together bits using the amazing abilities of OCUK members.
 
Thank you!

From one Jim to another....
i don't suppose you could help me out with one last small problem?

I'm trying to change the font by using the imagettftext() function instead of imagestring.

but i mess it up every single time......................
 
Back
Top Bottom