473,395 Members | 1,885 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,395 software developers and data experts.

php, GD library, Content-type

Hello,
I've managed to get as far as using some of the GD2 drawing functions
included in the php_gd2.dll. I can't figure out how to put HTML and
PHP output on the same browser page, no doubt this has something to
do with the header; any help would be greatly appreciated.
Thank you,
Gerard

<?php
header ("Content-type: image/png");

$t = imagecreate(400,150); // create a blank canvas
$c = imagecolorallocate($t,0,255,0); // set color for the first
thing
imagefilledrectangle($t,10,10,50,50,$c); // draw a rectange
$c = imagecolorallocate($t,215,20,20); // set color for the next
imagefilledellipse($t,50,50,75,75,$c); // draw an ellipse
$w = "it's not easy to learn this stuff!";
$c = imagecolorallocate($t,50,50,150);
imagestring($t,4,100,70,$w,$c);
imagepng($t); // output the image
imagedestroy($t); // clear memory, but not the browser

/* NOTHING FOLLOWING OUTPUTS */

echo "<pre>";
var_dump(gd_info());
echo "</pre>";

?>

Aug 6 '07 #1
5 1754
ge******@indigo.ie wrote:
Hello,
I've managed to get as far as using some of the GD2 drawing functions
included in the php_gd2.dll. I can't figure out how to put HTML and
PHP output on the same browser page, no doubt this has something to
do with the header; any help would be greatly appreciated.
Thank you,
Gerard

<?php
header ("Content-type: image/png");

$t = imagecreate(400,150); // create a blank canvas
$c = imagecolorallocate($t,0,255,0); // set color for the first
thing
imagefilledrectangle($t,10,10,50,50,$c); // draw a rectange
$c = imagecolorallocate($t,215,20,20); // set color for the next
imagefilledellipse($t,50,50,75,75,$c); // draw an ellipse
$w = "it's not easy to learn this stuff!";
$c = imagecolorallocate($t,50,50,150);
imagestring($t,4,100,70,$w,$c);
imagepng($t); // output the image
imagedestroy($t); // clear memory, but not the browser

/* NOTHING FOLLOWING OUTPUTS */

echo "<pre>";
var_dump(gd_info());
echo "</pre>";

?>
You can't. If it's an image, it isn't html - and vice versa.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 6 '07 #2
First save the image, then call it, or call this script thruoogh another
(wich contains the html/php)
On 06-08-2007 14:56, in article yR*******************@news.indigo.ie,
"ge******@indigo.ie" <ge******@indigo.iewrote:
Hello,
I've managed to get as far as using some of the GD2 drawing functions
included in the php_gd2.dll. I can't figure out how to put HTML and
PHP output on the same browser page, no doubt this has something to
do with the header; any help would be greatly appreciated.
Thank you,
Gerard

<?php
header ("Content-type: image/png");

$t = imagecreate(400,150); // create a blank canvas
$c = imagecolorallocate($t,0,255,0); // set color for the first
thing
imagefilledrectangle($t,10,10,50,50,$c); // draw a rectange
$c = imagecolorallocate($t,215,20,20); // set color for the next
imagefilledellipse($t,50,50,75,75,$c); // draw an ellipse
$w = "it's not easy to learn this stuff!";
$c = imagecolorallocate($t,50,50,150);
imagestring($t,4,100,70,$w,$c);
imagepng($t); // output the image
imagedestroy($t); // clear memory, but not the browser

/* NOTHING FOLLOWING OUTPUTS */

echo "<pre>";
var_dump(gd_info());
echo "</pre>";

?>
Aug 6 '07 #3
On 06.08.2007 14:56 ge******@indigo.ie wrote:
Hello,
I've managed to get as far as using some of the GD2 drawing functions
included in the php_gd2.dll. I can't figure out how to put HTML and
PHP output on the same browser page, no doubt this has something to
do with the header; any help would be greatly appreciated.
Thank you,
Gerard
hi there

just a few lines:

<?php
if(key($_GET) == 'img') {
header ("Content-type: image/png");

$t = imagecreate(400,150); // create a blank canvas
$c = imagecolorallocate($t,0,255,0); // set color for the first
thing
imagefilledrectangle($t,10,10,50,50,$c); // draw a rectange
$c = imagecolorallocate($t,215,20,20); // set color for the next
imagefilledellipse($t,50,50,75,75,$c); // draw an ellipse
$w = "it's not easy to learn this stuff!";
$c = imagecolorallocate($t,50,50,150);
imagestring($t,4,100,70,$w,$c);
imagepng($t); // output the image
imagedestroy($t); // clear memory, but not the browser
die(); }
/* NOTHING FOLLOWING OUTPUTS */

echo "<pre>";
var_dump(gd_info());
echo "</pre>";
echo "<img src={$_SERVER['PHP_SELF']}?img>";
?>
hope this helps.

PS Looks like you need a better understanding on how http and browsers
work, do some reading on this.

--
gosha bine

makrell ~ http://www.tagarga.com/blok/makrell
php done right ;) http://code.google.com/p/pihipi
Aug 6 '07 #4
gosha bine <st********@gmail.comwrote:
>hi there
>just a few lines:
><?php
>if(key($_GET) == 'img') {
>header ("Content-type: image/png");

$t = imagecreate(400,150); // create a blank canvas
$c = imagecolorallocate($t,0,255,0); // set color for the first
thing
imagefilledrectangle($t,10,10,50,50,$c); // draw a rectange
$c = imagecolorallocate($t,215,20,20); // set color for the next
imagefilledellipse($t,50,50,75,75,$c); // draw an ellipse
$w = "it's not easy to learn this stuff!";
$c = imagecolorallocate($t,50,50,150);
imagestring($t,4,100,70,$w,$c);
imagepng($t); // output the image
imagedestroy($t); // clear memory, but not the browser
>die(); }
>/* NOTHING FOLLOWING OUTPUTS */

echo "<pre>";
var_dump(gd_info());
echo "</pre>";
>echo "<img src={$_SERVER['PHP_SELF']}?img>";
>?>
>hope this helps.
>PS Looks like you need a better understanding on how http and browsers
work, do some reading on this.
Thanks very much, that works beautifully; I have only a vague idea
why, so I hope you don't mind a question or two about it.
1) I presume that <img src=etcsends a GET request to the server,
something like thisFile.php?keyName. The server then looks at the
file again, sees an 'img' key in $_GET and processes the script?
2) I know key() returns the key currently pointed to in the $_GET
array, but there's no way I can see the content of that array, is
there? I did a var_dump($_GET) but that shows an empty array.

As you said, I have a LOT of reading to do :-) I spent a few
hours last night searching; a Google on "http and web browsers"
got many hits on specific browsers and the RFC on HTTP, but little
of the information was useful in the context of understanding scripts
like the above. If you could suggest any resources, that would be
much appreciated too.

Thanks again,
Gerard

Aug 7 '07 #5
On 07.08.2007 12:05 ge******@indigo.ie wrote:
Thanks very much, that works beautifully; I have only a vague idea
why, so I hope you don't mind a question or two about it.
That's what we are here for. ;)
1) I presume that <img src=etcsends a GET request to the server,
something like thisFile.php?keyName. The server then looks at the
file again, sees an 'img' key in $_GET and processes the script?
Correct, you got it: acquiring html file and image are two distinct and
absolutely independent requests in http.
2) I know key() returns the key currently pointed to in the $_GET
array, but there's no way I can see the content of that array, is
there? I did a var_dump($_GET) but that shows an empty array.
When you script is called with a single parameter name, without a value,
the $_GET array looks like:

array('param_name' ='') <-- empty string
As you said, I have a LOT of reading to do :-) I spent a few
hours last night searching; a Google on "http and web browsers"
got many hits on specific browsers and the RFC on HTTP, but little
of the information was useful in the context of understanding scripts
like the above. If you could suggest any resources, that would be
much appreciated too.
I'd start here http://en.wikipedia.org/wiki/HTTP

Also, "http sniffer" tools (that show the traffic from and to your
browser) are very useful to understand what's going on. FireBug (firefox
extension) includes such a tool.
--
gosha bine

makrell ~ http://www.tagarga.com/blok/makrell
php done right ;) http://code.google.com/p/pihipi
Aug 7 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Rob Long | last post by:
Hey, I've written a custom HTML library using many PHP scripts as seperate files (just like I'd do a java project) and I'm having some problems where I'm including scripts in different...
0
by: libreria ledi international bookseller | last post by:
BIBLIOTECA DIGITALE THE ITALIAN EBOOK PLATFORM FOR LIBRARIES Libraries’ users ask for more and more accessible information and for even more complete and updated catalogues. The Italian...
3
by: Alpesh Parmar | last post by:
Hi Frens, I've made a class library project in Visual Basic using visual studio.net 2003. Now after i m done I copy the dll from the \bin dir. of this project to my web application project using...
5
by: Marcel Gelijk | last post by:
Hi, I am trying to create a User Control that is located in a seperate class library. The User Control contains a textbox and a button. The page generates an exception when it tries to access...
1
by: darrel | last post by:
I have two issues: 1) The WYSIWYG content editor we're using for our CMS doesn't truly support xhtml. 2) .net doesn't truly support xhtml my question is if there is a .net...
2
by: Ben Finney | last post by:
Howdy all, I'm trying to implement some new functionality for an existing PHP web application. Rather than writing a whole lot of stuff in PHP, and looking toward a future when more of the...
87
by: Robert Seacord | last post by:
The SEI has published CMU/SEI-2006-TR-006 "Specifications for Managed Strings" and released a "proof-of-concept" implementation of the managed string library. The specification, source code for...
26
by: Andrew Poelstra | last post by:
I hacked this together this morning so that I could shift my out-of- space code away from the rest of my logic. I wanted to allow array syntax on my dynamic buffers, so I manually created a struct...
3
by: tuka | last post by:
Hi All, Is there a way to temporarily suspend the use of imported libraries in xslt ? To be precise the issue I am trying to resolve is , I have a library imported as <xsl:import...
2
by: Frank | last post by:
Hi, Originally I was planning to do some code reuse (yeah.. that exists..didn't want to believe it either) with some class library projects that I now want to use in a asp.net 2.0 web app in VS...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.