I would like to create an image from an included PHP file, there is an error of undefined variable:
index.php
<?php
// get servers and domains
$serSel = 'SELECT * FROM servers';
$serReq = $connexion->query($serSel);
$serRes = $serReq->fetchAll();
$totalSer = count($serRes);
foreach($serRes as $Serv)
{
$s_global_size = $Serv['s_global_size'];
$s_used_size = $Serv['s_used_size'];
$s_creation = $Serv['s_creation'];
$s_expiry = $Serv['s_expiry'];
$diskSpace = ($e_name == 'domain') ? '-' : format_bytes($s_global_size);
echo $diskSpace;
$diskUsage = ($e_name == 'domain') ? '-' : format_bytes($s_used_size);
echo $diskUsage;
$s_left_size = ($s_global_size - $s_used_size);
$sLeftSize = ($e_name == 'domain') ? '-' : format_bytes($s_left_size);
echo $sLeftSize;
}
echo '<img src="Idara/Statistics/webdata_circle.php">';
?>
webdata_circle.php
<?php
// create image
$image = imagecreatetruecolor(180, 180);
$usagePerc = ($diskUsage * 360)/$diskSpace;
// allocate some colors
$red = imagecolorallocate($image, 192, 0, 0);
$red1 = imagecolorallocate($image, 192, 20, 0);
$green = imagecolorallocate($image, 0, 133 ,62);
$green1 = imagecolorallocate($image, 0, 140 ,62);
$trans = imagecolorallocate($image, 0, 0, 0); // transparent background
// Make the background transparent
imagecolortransparent($image, $trans);
imagefilledarc($image, 80, 80, 150, 150, 0, 360, $red, IMG_ARC_PIE);
imagefilledarc($image, 80, 80, 150, 150, 0, $usagePerc, $green, IMG_ARC_PIE);
// flush image
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>
The error returned is:
PHP Notice: Undefined variable: diskUsage in webdata_circle.php on line 8
PHP Notice: Undefined variable: diskSpace in webdata_circle.php on line 8
PHP Warning: Division by zero in webdata_circle.php on line 8
Thanks in advance
NB: This is the full code, I hope it will help
You need to add the following lines to webdata_circle.php, on the 2nd line:
$diskPath = dirname(__FILE__);
$diskUsage = disk_total_space ($diskPath);
$diskUsage = disk_free_space ($diskPath);
Related
I got this code to work but after few weeks the code is not working ,i did try to see where the bug come from but i have no idea.
I did create image with GD library and it is created successfully but when i want to merge it with another picture it show only black screen.Any idea of how to solve the issue please .Here is my code:
Please note that the image is created and saved successfully,so there is no problem with create_image() function.
function create_image()
{
$cer_id = get_the_ID();
$cer_org_nummer = get_field('orgnummer_dqm');
$cer_today = date('Y-m-d');
$cer_org_name = get_field('foretags_namn_dqm');
$cer_org_date = $cer_org_nummer . ' | ' . $cer_today;
$im = #imagecreate(500, 450);
$yellow = imagecolorallocate($im, 255, 255, 255); // yellow
imagecolortransparent($im, $yellow);
$black = imagecolorallocate($im, 252, 195, 91);
$string = "Digital Quality Managment";
$font = FUNC_PLUGIN_D_DQM . '/font/Roboto-Regular.ttf';// black
/* imagestring($im, $font, 50, 300, $string, $black);*/
/* imagestring($im, $font, 3, 300, $cer_org_name, $black);*/
/* imagestring($im, $font, 0, 10, $cer_org_date, $black);*/
imagettftext($im, 35, 0, 60, 270, $black, $font, 'CERTIFIED');
imagettftext($im, 25, 0, 0, 320, $black, $font, $cer_org_date);
imagepng($im, "wp-content/plugins/certificates/cer_images/image_$cer_id.png");
imagedestroy($im);
}
create_image();
$image1 = "wp-content/plugins/certificates/cer_images/dqm_png_logo.png";
$image2 = "wp-content/plugins/certificates/cer_images/image_$cer_id.png";
list($width, $height) = getimagesize($image2);
$image1 = imagecreatefromstring(file_get_contents($image1));
$image2 = imagecreatefromstring(file_get_contents($image2));
imagealphablending($image1, FALSE);
imagesavealpha($image1, TRUE);
imagecopymerge($image1, $image2, 110, 50, 0, 0, $width, $height, 100);
header("Content-type: image/png");
imagepng($image1);
imagedestroy($image1);
please try the code below
This code works for me..
$pro_directory_path = get_attached_file( get_post_thumbnail_id($_REQUEST['apid']),'full' );
$mainmetadata = wp_get_attachment_metadata( get_post_thumbnail_id( $_REQUEST['apid'] ) );
$pro_img_name = $mainmetadata['file'];
$pro_img_name_extra = '1'.$mainmetadata['file'];
// $val_id is id of image(bigger image/background Image)
$directory_path = get_attached_file( $val_id,'full' );
$metadata = wp_get_attachment_metadata( $val_id );
$name = $metadata['file'];
$bgFile = $directory_path;
// We want our final image to be 76x76 size
//user $metadata to get ordiginal height width of image
// $value contain height width of wall mentioned by admin
$x = $metadata['width'];
$y = $metadata['height'];
$x_inch = $metadata['width']/96;
$y_inch = $metadata['height']/96;
$width_proption = $wall_w_inch/$x_inch;
$height_proption = $wall_h_inch/$y_inch;
$img_pos_x = ($x/2)-($resizedwidth/2);
$img_pos_y = ($y/2)-($resizedheight);
/* Code to generate custom wall images - STart */
$inn_width = ($innerimg_width / $width_proption) * 12 ;
$inn_height = ($innerimg_height / $height_proption) * 12 ;
$resizedFilename = get_template_directory().'/woocommerce/temp_images/cust_'.$pro_img_name;
$img_url_extra = get_stylesheet_directory_uri().'/woocommerce/temp_images/cust_'.$pro_img_name;
//function to resize Artist product image in desired size's (Variation sizes).
$imgData = resize_image($pro_directory_path, $inn_width, $inn_height);
imagepng($imgData, $resizedFilename);
list($resizedwidth, $resizedheight) = getimagesize($resizedFilename);
/* Code to generate custom wall images - ENDS */
$imageFile = $resizedFilename;
// dimensions of the final image
$final_img = imagecreatetruecolor($x, $y);
// Create our image resources from the files
$image_1 = imagecreatefrompng($bgFile);
$image_2 = imagecreatefrompng($imageFile);
// Enable blend mode and save full alpha channel
imagealphablending($final_img, true);
imagesavealpha($final_img, true);
// Copy our image onto our $final_img
imagecopy($final_img, $image_1, 0, 0, 0, 0, $x, $y);
imagecopy($final_img, $image_2, $img_pos_x, $img_pos_y, 0, 0, $resizedwidth, $resizedheight);
ob_start();
$path = __DIR__ .'/custom_wall_img/'.$name;
imagepng($final_img,$path);
$watermarkedImg = ob_get_contents(); // Capture the output
ob_end_clean(); // Clear the output buffer
Okay.. so I've been trying to make a 'signature' for a game that I play.
The only catch is, I've been running into quite a few problems when wanting to insert an Avatar & Online/Offline image.
The two things I've been trying to do is:
Get user status from a webpage habplus.com/home/[username] by checking if habbo_offline.gif is present.
if(strpos(file_get_contents('http://www.habpl.us/home/'.$username.''),
'habbo_offline.gif') == true) {
Grab users image and display on the final image
function habSigFigure($username){
$omgfig = 'http://www.habpl.us/figure.php?user='.$username.'&img_format=gif';
return $omgfig;
//place habbo avatar
$habsigfig = imagecreatefromgif($omgfig);
imagecopy($img, $habsigfig, 13, 32, 0, 0, imagesx($habsigfig), imagesy($habsigfig));*/
//place habbo avatar
I've included the entire source code, and the and the page can be accessed here
-Another link with variables included
Hope you can help..
Sincerely yours, Malmoc
<?php
include 'config.php';
$username=$_REQUEST["user"];
$grabstat3 = fopen("http://habplus.com/fansitetools/userStats.php?user={$username}&stat=motto", "r");
while (!feof($grabstat3)){ $motto1 = fgets($grabstat3);
}
fclose($grabstat3);
$username=$_REQUEST["user"];
$grabstat2 = fopen("http://habplus.com/fansitetools/userStats.php?user={$username}&stat=pixels", "r");
while (!feof($grabstat2)){ $pixels1 = fgets($grabstat2);
}
fclose($grabstat2);
$username=$_REQUEST["user"];
$grabstat1 = fopen("http://habplus.com/fansitetools/userStats.php?user={$username}&stat=credits", "r");
while (!feof($grabstat1)){ $credits1 = fgets($grabstat1);
}
fclose($grabstat1);
$pixels = 'Pixels: '.$pixels1.'';
$credits = 'Credits: '.$credits1.'';
$motto = 'Motto: '.$motto1.'';
/* Get custom img */
if(empty($_REQUEST['img'])){
$img = 'default.png';
}else{
$img =$_REQUEST['img'];
}
/* TEXT COLORS */
$red =$_REQUEST['red'];
$green =$_REQUEST['green'];
$blue =$_REQUEST['blue'];
/* Font size */
$fsize =$_REQUEST['fsize'];
/*function habSigStatus($username){
if(strpos(file_get_contents('http://www.habpl.us/home/'.$username.''), 'habbo_offline.gif') == true){
return false;
}else{
return true;
function habSigFigure($username){
$omgfig = 'http://www.habpl.us/figure.php?user='.$username.'&img_format=gif';
return $omgfig;
}
}
}*/
/*
//place habbo avatar
$habsigfig = imagecreatefromgif($omgfig);
imagecopy($img, $habsigfig, 13, 32, 0, 0, imagesx($habsigfig), imagesy($habsigfig));*/
//place habbo avatar
//habbo status
if(strpos(file_get_contents('http://www.habpl.us/home/'.$username.''), 'habbo_offline.gif') == true){
$status_img = imagecreatefromgif('habbo_offline.gif');
}else{
$status_img = imagecreatefromgif('habbo_online.gif');
}
imagecopy($image, $status_img, 403, 96, 0, 0, 50, 16);
//habbo status
$image = imagecreatefrompng($img);
$font_color = imagecolorallocate($image, $red, $green, $blue);
imagefttext($image, $fsize, 0, 3, 12, $font_color, './volt.ttf', $credits); /* top left */
imagefttext($image, $fsize, 0, 403, 12, $font_color, './volt.ttf', $pixels); /* top right */
imagefttext($image, $fsize, 0, 3, 96, $font_color, './volt.ttf', $motto); /* bottom left */
imagefttext($image, $fsize, 0, 403, 96, $font_color, './volt.ttf', $online); /* bottom right */
/* imagefttext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text [, array $extrainfo]) */
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>
$image should be a valid resource, in your code $image is null
$image = imagecreatefrompng($img);
imagecopy($image, $status_img, 403, 96, 0, 0, 50, 16);
you can use
$image = imagecreatetruecolor(50, 16); //width,height
imagecopy($image, $status_img, 403, 96, 0, 0, 50, 16);
Here's your problem, fairly derpy to be honest:
imagecopy($image, $status_img, 403, 96, 0, 0, 50, 16);
$image = imagecreatefrompng($img);
You kind of need to create the image before you can copy to it. Swap those two lines around and you should be good.
I have a problem , I have a software that gets pc tech specs and post them online and we are offering a signature image for each specs, this is created by php , but is not working anymore;
Demo link : http://checkmyspecs.co.uk/button.php?id=646725 or go to any specs page , example : http://www.checkmyspecs.co.uk/display2.php?id=646725 and down on the page is grab button code.
The image must be created by button.php , here is the code :
<?php
include "db.php";
function getdata($viewerid) {
$query = "SELECT * FROM data where viewerid = '$viewerid'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());
$data = array();
array_push($data,$row['bootmethod'],$row['ComputerCaption'],$row['Infrared'],$row['DayLight'],$row['ManufacturerBox'],$row['Model'],$row['cores'],$row['memory'],$row['monitor'],$row['resolution'],$row['pixels'],$row['cpuvoltage'],$row['clockspeed'],$row['AddressWidth'],$row['SocketDesignation'],$row['cpuname'],$row['loadpercent'],$row['applications'],$row['videocardname'],$row['refreshrate'],$row['videodriver'],$row['installed'],$row['hddata'],$row['directx']);
return $data;
}
function LoadPNG($imgname,$cur)
{
$getvalues = getdata($cur);
/* Attempt to open */
$im = #imagecreatefrompng($imgname);
// Removes white background (made from the original transparency)
$white = imagecolorallocate($im, 255, 255, 255);
// Make the background transparent
//Generate the text to write onto the image (the php Version).
//Don't know much about this
// Add some shadow to the text
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
$blue = imagecolorallocate($im, 0, 173, 238);
$darkblue = imagecolorallocate($im, 54, 154, 191);
$font = '/fonts/arialbd.ttf';
$ramo = $getvalues[7];
$cpuo = $getvalues[15];
$gpuo = $getvalues[18];
$screeno = $getvalues[9];
$ram = "$ramo MB";
$cpu = "$cpuo";
$gpu = "$gpuo ";
$screen = "$screeno";
imagettftext($im, 11, 0, 40, 23, $black, $font, $cpu);
imagettftext($im, 11, 0, 40, 53, $black, $font, $gpu);
imagettftext($im, 11, 0, 40, 83, $black, $font, $screen);
imagettftext($im, 11, 0, 40, 113, $black, $font, $ram);
// write text
$textcolor = imagecolorallocate($im, 0, 3, 0);
return $im;
}
header('Content-Type: image/png');
$button = '/images/button.png';
$img = LoadPNG($button,$_GET['id']);
imagepng($img);
?>
Your image isn't an image. Here's what is really being output:
Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/checkmys/public_html/button.php on line 24
Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/checkmys/public_html/button.php on line 33
Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/checkmys/public_html/button.php on line 34
Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/checkmys/public_html/button.php on line 35
Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/checkmys/public_html/button.php on line 36
Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/checkmys/public_html/button.php on line 37
Fatal error: Call to undefined function imagettftext() in /home/checkmys/public_html/button.php on line 53
You can use tools such as Fiddler to see this, even when your content-type is set as an image. If you would remove that # symbol, we could see the error describing why your image could not be created.
Also, you are currently wide open to SQL injection. You should use prepared queries with PDO to avoid this problem.
I have the following code validation php script:
if(empty($_POST['captcha_code'])) {
$error = 1;
$code[3] = 'color:#FF0000;';
} else {
include_once "formfiles/captcha.php";
$randomnr = new Securimage();
$valid = $randomnr->check($_POST['captcha_code']);
if(!$valid) {
$error = 1;
$code[3] = 'color:#FF0000;';
$code[4] = '<strong><span style="color:#FF0000;">Incorrect code</span></strong>';
}
}
and this captcha php code:
<?php
Securimage();
exit();
function Securimage()
{
$randomnr = rand(1000, 9999);
$_SESSION['randomnr2'] = md5($randomnr);
$im = imagecreatetruecolor(100, 38);
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 150, 150, 150);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 200, 35, $black);
//path to font - this is just an example you can use any font you like:
$font = dirName(__FILE__).'/calvin.ttf';
imagettftext($im, 20, 4, 22, 30, $grey, $font, $randomnr);
imagettftext($im, 20, 4, 15, 32, $white, $font, $randomnr);
imagegif($im);
imagedestroy($im);
}
?>
After submitting my form I always get an awkward bit of code starting with gif. Where is my fault? Can somebody please help me?
You need to decalare header about the content type to browser recognize it as image. Try this
header('Content-Type: image/gif');
Securimage();
exit();
How can i generate multiple texts using the imagecreatetruecolor() method? I have the following code, but this displays either the first font or the second - not both:
<?php
// Set the content-type
header('Content-type: image/png');
// The text to draw
$text = 'Hello Farooqi';
$x = 0;
$y = 0;
$w = 50;
$h = 50;
$s = 13;
// Create the image
$im = imagecreatetruecolor($w , $s);
imagesavealpha($im, true);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im,0,0,0);
$text_color = imagecolorallocate($im, 200,200, 91);
$blue = imagecolorallocate($im,0,0,180);
$alpha = imagecolorallocatealpha($im, 0, 0, 0, 127);
//imagefilledrectangle($im, 0, 0, 150, 25, $black);
imagefill($im, 0, 0, $alpha);
// Replace path by your own font path
$font = 'Calibri Bold.ttf';
// Add the text
$dimensions = imagettftext($im, $s, 0, $x, $y, $black, $font, $text);
$textWidth = ($dimensions[2]);
$imm = imagecreatetruecolor($w , $s);
imagesavealpha($imm, true);
$bluem = imagecolorallocate($imm,50,50,50);
$alpham = imagecolorallocatealpha($imm, 0, 0, 0, 127);
imagefill($imm, 0, 0, $alpham);
imagettftext($imm, $s, 0, $x+3, $y+3, $bluem, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagepng($imm);
imagedestroy($im);
imagedestroy($imm);
?>
Here above in these last 4 lines only one line appears, and that's the first one. How can I have both lines?
Please help. Thanks in advance.
The imagepng($im); will be called and outputted to your HTML code and as the header is set to an image it will display this image. No matter your imagepng($inm) that comes afterwards.
A better way would be to create two different PHP files. One that does your script and ends in imagepng($im); and another one that ends in imagepng($inm);
And then in your master PHP (header = text/html) file you just mention these 2 files in your image source:
<img src="functions/first_image.php" />
<img src="functions/second_image.php" />