...

View Full Version : Question about imagepng()



Rappa
02-19-2010, 02:39 AM
So I have a html form which takes values and places them on an image using coordinates and the imagepng() function. Everything works fine after the user submits the form. But i'm trying to add a print button on the page but every time I try to add buttons I get header errors, I tried adding the php to the body, and putting the html before and after the php, and I cant get anything to work. So, I was wondering if theres something I need to do to the image before I can add other content to the page.

Any ideas?

If it helps:


<?php

$font_size = 10;
$font_file = 'calibri.ttf';
$image_front = 'http://imgur.com/OeRqF.jpg';
$image = imagecreatefromjpeg($image_front);
$font_color = imagecolorallocate($image, 23, 50, 115);

//Date
imagettftext($image, $font_size, 0, 80, 270, $font_color, $font_file, $_POST['date']);
//Name
imagettftext($image, $font_size, 0, 210, 270, $font_color, $font_file, $_POST['name']);

//Certification
$x = 'X';
$x2 = 'x';

if($_POST['certification'] == 'cc'){
imagettftext($image, $font_size, 0, 436, 270, $font_color, $font_file, $x);
}
else if($_POST['certification'] == 'p'){
imagettftext($image, $font_size, 0, 510, 270, $font_color, $font_file, $x);
}

//EMT Number
imagettftext($image, $font_size, 0, 90, 295, $font_color, $font_file, $_POST['emtnumber']);

//Agency
imagettftext($image, $font_size, 0, 240, 295, $font_color, $font_file, $_POST['agency']);

//Type of CPAP Used
imagettftext($image, $font_size, 0, 170, 320, $font_color, $font_file, $_POST['typecpap']);

//Age
imagettftext($image, $font_size, 0, 75, 380, $font_color, $font_file, $_POST['age']);

//Gender
if($_POST['gender'] == 'm'){
imagettftext($image, $font_size, 0, 130, 382, $font_color, $font_file, $x);
}
else if($_POST['gender'] == 'f'){
imagettftext($image, $font_size, 0, 185, 382, $font_color, $font_file, $x);
}

//Severity
if($_POST['respdistress'] == 'moderate'){
imagettftext($image, $font_size, 0, 388, 382, $font_color, $font_file, $x);
}
else if($_POST['respdistress'] == 'severe'){
imagettftext($image, $font_size, 0, 463, 382, $font_color, $font_file, $x);
}

//Vitals 1
imagettftext($image, $font_size, 0, 165, 425, $font_color, $font_file, $_POST['resp1']);
imagettftext($image, $font_size, 0, 228, 425, $font_color, $font_file, $_POST['pulse1']);
imagettftext($image, $font_size, 0, 278, 425, $font_color, $font_file, $_POST['systolic1']);
imagettftext($image, $font_size, 0, 308, 425, $font_color, $font_file, $_POST['diastolic1']);
imagettftext($image, $font_size, 0, 370, 425, $font_color, $font_file, $_POST['o2sat1']);
imagettftext($image, $font_size, 0, 455, 425, $font_color, $font_file, $_POST['et1']);
//ECG 1
imagettftext($image, $font_size, 0, 130, 445, $font_color, $font_file, $_POST['ecg1']);

//Vitals 2
imagettftext($image, $font_size, 0, 165, 468, $font_color, $font_file, $_POST['resp2']);
imagettftext($image, $font_size, 0, 228, 468, $font_color, $font_file, $_POST['pulse2']);
imagettftext($image, $font_size, 0, 278, 468, $font_color, $font_file, $_POST['systolic2']);
imagettftext($image, $font_size, 0, 308, 468, $font_color, $font_file, $_POST['diastolic2']);
imagettftext($image, $font_size, 0, 412, 468, $font_color, $font_file, $_POST['o2sat2']);
imagettftext($image, $font_size, 0, 490, 467, $font_color, $font_file, $_POST['et2']);
//ECG 2
imagettftext($image, $font_size, 0, 130, 489, $font_color, $font_file, $_POST['ecg2']);

//CO2
imagettftext($image, $font_size, 0, 362, 489, $font_color, $font_file, $_POST['co21']);
imagettftext($image, $font_size, 0, 430, 489, $font_color, $font_file, $_POST['co22']);

//Reason for CPAP use
if($_POST['reason'] == 'PE'){
imagettftext($image, $font_size, 0, 86, 532, $font_color, $font_file, $x2);
}
else if($_POST['reason'] == 'other'){
imagettftext($image, $font_size, 0, 230, 532, $font_color, $font_file, $x2);
}
//Other Medical Control
imagettftext($image, $font_size, 0, 345, 532, $font_color, $font_file, $_POST['othermedcontrol']);

//Significant Effect
if($_POST['feel'] == 'improved'){
imagettftext($image, $font_size, 0, 86, 575, $font_color, $font_file, $x2);
}
else if($_POST['feel'] == 'worsened'){
imagettftext($image, $font_size, 0, 158, 575, $font_color, $font_file, $x2);
}
else if($_POST['feel'] == 'none'){
imagettftext($image, $font_size, 0, 266, 575, $font_color, $font_file, $x2);
}

//Clinical Impression
imagettftext($image, $font_size, 0, 250, 595, $font_color, $font_file, $_POST['impression']);

//How long on CPAP
imagettftext($image, $font_size, 0, 322, 616, $font_color, $font_file, $_POST['howlong']);

//Complications
if($_POST['complications'] == 'yes'){
imagettftext($image, $font_size, 0, 339, 638, $font_color, $font_file, $x2);
}
else if($_POST['complications'] == 'no'){
imagettftext($image, $font_size, 0, 398, 638, $font_color, $font_file, $x2);
}

//What/Why
imagettftext($image, $font_size, 0, 100, 658, $font_color, $font_file, $_POST['whatwhy']);

//Care without CPAP
if($_POST['lastquestion'] == 'intubation'){
imagettftext($image, $font_size, 0, 178, 705, $font_color, $font_file, $x2);
}
else if($_POST['lastquestion'] == 'bvm'){
imagettftext($image, $font_size, 0, 286, 705, $font_color, $font_file, $x2);
}
else if($_POST['lastquestion'] == 'nrb'){
imagettftext($image, $font_size, 0, 358, 705, $font_color, $font_file, $x2);
}

//Date stamp
$d = date("m-d-Y, h:i A");

//Make image, store it in forms folder with date extension
Header("Content-type: image/png");
imagepng($image);
imagepng($image,'forms/audit' . '_' . $d . '.png');

//Make file to hold count for temp images
$fp = fopen("form.txt", "r");
$count = fread($fp, 1024);
fclose($fp);
$count = $count + 1;
$fp = fopen("form.txt", "w");
fwrite($fp, $count);

//Make temp images for emailing
imagepng($image,'forms/temp/audit_temp' . $count . '.png');
fclose($fp);

//Kill resources
imagedestroy($image);
?>



Go easy, i'm not exactly the greatest web programmer.

Thanks for any help.

- Anthony

_Aerospace_Eng_
02-19-2010, 04:05 AM
That is because you are sending a header with that image. It would be better to redirect to some page and then use the image tag with the src being the generated image. Now the page you redirected to is just a simple html page which you can put buttons on.

Rappa
02-19-2010, 04:22 AM
Example, possibly?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum