473,795 Members | 3,167 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using GD Library Functions

I would like use some of the GD image functions, so I ran a couple of
short scripts to see if it worked, such as:

<?php

/* Create a red square */
$image = imagecreate(200 , 200);
$colorRed = imagecoloralloc ate($image, 255, 0, 0);
imagefill($imag e, 0, 0, $colorRed);

//send image
header("Content-type: image/jpeg");
imagejpeg($imag e);

?>

but all they generates are garbage characters and no image, starting
with:
ÿØÿàJFIFÿþ >CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default
quality ÿÛC ... (etc.)

I then ran a script to see what version was installed
(var_dump(gd_in fo());)and it generated: ["GD Version"]=> string(24)
"bundled (2.0 compatible)"
So why doesn't it generate a jpeg? Am I doing something incorrectly or
is it the library itself? (This is using a hosting account at
godaddy.com. It is not PHP or a GD library that I installed).

Thanks,
Eric
Jul 17 '05
15 19105
"CountScubu la" <me@scantek.hot mail.com> wrote in message news:<KD******* **********@news svr27.news.prod igy.com>...

there should bo NO body section, we (i assume everyone else here) thought
that was your complete script.

you are to send out a <BODY> tag if you are sending out an .html page,
becouse html pages continain, a body.

when you are sending out image data, send out only image data.

Think of it not as html with php in it, but rather a scripting lanugage
thats send out plain data outside the <?php ?> tags

so, with this line of though, php can send out any type of data. in fact
some people (myself included) dont have any text outside the <?php ?> tags,
and use it soley as a scripting laguage.

now, if a script needed to send, lets say the <HTML> tag, 2 ways

<HTML>
<?php
some script....
?>
</HTML>

or

<?php
print "<HTML>\n";
some script...
print "</HTML>\n";
?>

so you see, anything outside the <?php ?> tags is send directly to the
browser.


Interesting. OK, and I find out from the php.net site that for the
imagejpeg() function that "The filename argument is optional, and if
left off, the raw image stream will be output directly."
(http://www.php.net/manual/en/function.imagejpeg.php)

So that's why one gets either text garbage or an image and nothing
else - it's just an image that's output DIRECTLY to the browser.

So... if I wanted to create the image and have my cake and eat it too,
I could (supposedly) save it and then display it with an HTML image
tag, like:

<html>
<head>
<title>Listin g 12-2a</title>
</head>

<body>
<?php
/* Create a red square */
$image = imagecreate(200 , 200);
$colorRed = imagecoloralloc ate($image, 255, 0, 0);
imagefill($imag e, 0, 0, $colorRed);

//save image then use later
imagejpeg($imag e, "pic.jpg");
imagedestroy($i mage);
?>

<img src="pic.jpg" border=0>
<br>Here is some text.
</body>
</html>
Well, I tried this but it can't find (doesn't display) the image.
Where'd it go? I looked in my hosting account directories but couldn't
find it anywhere. I assumed it would appear in the directory where the
PHP script was run.
Jul 17 '05 #11
On 2004-01-04, Uncle_Alias <ze*********@ya hoo.com> wrote:
<?php
/* Create a red square */
$image = imagecreate(200 , 200);
$colorRed = imagecoloralloc ate($image, 255, 0, 0);
imagefill($imag e, 0, 0, $colorRed);

//save image then use later
imagejpeg($imag e, "pic.jpg");
imagedestroy($i mage);
?>

<img src="pic.jpg" border=0>
<br>Here is some text.
</body>
</html>
Well, I tried this but it can't find (doesn't display) the image.
Where'd it go? I looked in my hosting account directories but couldn't
find it anywhere. I assumed it would appear in the directory where the
PHP script was run.


This way, you need to make sure that the user which is running
apache/php (usually nobody or www-data) has the rights to write such a
file at that place.
--
verum ipsum factum
Jul 17 '05 #12
Tim Van Wassenhove wrote:
On 2004-01-04, Uncle_Alias <ze*********@ya hoo.com> wrote:
<?php
/* Create a red square */
$image = imagecreate(200 , 200);
$colorRed = imagecoloralloc ate($image, 255, 0, 0);
imagefill($imag e, 0, 0, $colorRed);

//save image then use later
imagejpeg($imag e, "pic.jpg");
imagedestroy($i mage);


<img src="pic.jpg" border=0>
<br>Here is some text.
</body>
</html>
Well, I tried this but it can't find (doesn't display) the image.
Where'd it go? I looked in my hosting account directories but
couldn't find it anywhere. I assumed it would appear in the
directory where the PHP script was run.


This way, you need to make sure that the user which is running
apache/php (usually nobody or www-data) has the rights to write such a
file at that place.


What tim said.

Also, note that if you have a page that's something like:
<?php
// this file is somepage.php
header(stuff for jpeg); // too lazy to remember syntax
....
imagejpeg($img) ;
?>

you can do
<img src="somepage.p hp">
Jul 17 '05 #13
tom
SwissCheese wrote:

"tom" <te**@nospam.co m> wrote in message
news:bt******** ***********@new s.demon.co.uk.. .
Randell D. wrote:
> "SwissChees e" <Sw*********@cf l.rr.com> wrote in message
> news:F8******** **************@ twister.tampaba y.rr.com...
> "Uncle_Alia s" <ze*********@ya hoo.com> wrote in message
> news:e1******** *************** ***@posting.goo gle.com...
>> I would like use some of the GD image functions, so I ran a couple of
>> short scripts to see if it worked, such as:
>>
>> <?php
>>
>> /* Create a red square */
>> $image = imagecreate(200 , 200);
>> $colorRed = imagecoloralloc ate($image, 255, 0, 0);
>> imagefill($imag e, 0, 0, $colorRed);
>>
>> //send image
>> header("Content-type: image/jpeg");
>> imagejpeg($imag e);
>>
>> ?>
>>
>> but all they generates are garbage characters and no image, starting
>> with:
>> ÿØÿàJFIFÿþ >CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default
>> quality ÿÛC ... (etc.)
>>
>> I then ran a script to see what version was installed
>> (var_dump(gd_in fo());)and it generated: ["GD Version"]=> string(24)
>> "bundled (2.0 compatible)"
>>
>>
>> So why doesn't it generate a jpeg? Am I doing something incorrectly or
>> is it the library itself? (This is using a hosting account at
>> godaddy.com. It is not PHP or a GD library that I installed).
>> Thanks,
>> Eric
>>
>
> Copied your script to my server and it worked just fine... you
> really
> don't even need the 'header...' line either...
>
> <?PHP
> $image = imagecreate(200 , 200);
> $colorRed = imagecoloralloc ate($image, 255, 0, 0);
> imagefill($imag e, 0, 0, $colorRed);
>
> //send image
> //header("Content-type: image/jpeg");
> imagejpeg($imag e);
> ?>
>
> here is a link: http://www.suddenimpactfans.com/getphoto3.php
>
> It could be a problem on your host side - although the only time I get
> text output from the GD stuff is if there is an error in one of the
> function calls...


help - I see loadsa junk on konqueror, and a few lines of junk with

netscape
thanks, tom


Try it now - I enabled the header line as Opera 7+ gave junk too, but now
doesn't with the header line.

worked - thanks (I still get this on my server though - and need to keep at
it), tom
Jul 17 '05 #14
"Agelmar" <if**********@c omcast.net> wrote in message news:<bt******* *****@ID-30799.news.uni-berlin.de>...
Tim Van Wassenhove wrote:
On 2004-01-04, Uncle_Alias <ze*********@ya hoo.com> wrote:
<?php
/* Create a red square */
$image = imagecreate(200 , 200);
$colorRed = imagecoloralloc ate($image, 255, 0, 0);
imagefill($imag e, 0, 0, $colorRed);

//save image then use later
imagejpeg($imag e, "pic.jpg");
imagedestroy($i mage);
<img src="pic.jpg" border=0>
<br>Here is some text.
</body>
</html>
Well, I tried this but it can't find (doesn't display) the image.
Where'd it go? I looked in my hosting account directories but
couldn't find it anywhere. I assumed it would appear in the
directory where the PHP script was run.


This way, you need to make sure that the user which is running
apache/php (usually nobody or www-data) has the rights to write such a
file at that place.


What tim said.

Also, note that if you have a page that's something like:
<?php
// this file is somepage.php
header(stuff for jpeg); // too lazy to remember syntax
...
imagejpeg($img) ;
?>

you can do
<img src="somepage.p hp">

Yeah, that works. Cool. Raises all kinds of possibilities.. .
Jul 17 '05 #15
"Randell D." <re************ **********@and. share.com> wrote in message news:<%NIJb.931 853$pl3.509732@ pd7tw3no>...

--
=============== =============== ======
Hi again,
I don't know why you couldn't get the above code to work... take a look at
http://ca3.php.net/manual/en/function.gd-info.php

If will tell you what functionality the gdlib can give you (this can vary
pending what libraries you have installed). The gd_info() function should
work on any PHP 4 forward...

If that doesn't work, try phpinfo(); and examine any mention of GD in its
output...

Lastly... when outputing an image, it is handled differently by the web
client than when sending text... It has to do with headers... this might be
the reason as to why you are getting mixed results from browser to
browser... Some browsers might attempt to be intelligent and guess what data
is being sent to them, while othes will just display the binary data that
makes up the image (aka junk to you and I). I would suggest that you write
your test image to a file first, then have your HTML request the image with
the html <img> tag.... Once you've solved that, then I'd go one step further
to work on dynamic images if that's your thing...

Replies please... via the newsgroup, so everyone can learn... and happy new
year,
Thanks,
Randell D.

phpinfo(); is disabled in the configuration of PHP at my hosting
account. I guess they don't want people hacking it?:
"The following functions have been disabled on our Unix servers:
fpassthru
file
mail
exec
system
passthru
popen
crack_check
crack_closedict
crack_getlastme ssage
crack_opendict
fsockopen
psockopen
opendir
readdir
closedir
phpinfo
all Posix functions"

Maybe this explains why gd_info() doesn't work. (It is PHP 4.3.1 BTW).
Funny thing is, I used the mail function in a small script, and it
worked. Go figure.

Eric
Jul 17 '05 #16

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

Similar topics

0
6706
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft Visual Basic .NET version of this article, see 308049. For a Microsoft Visual C++ .NET version of this article, see 310071. For a Microsoft Visual J# .NET version of this article, see 320627. This article refers to the following Microsoft .NET...
0
5221
by: Reed | last post by:
Can someone stear me in the right direction to convert a binary tree from a Linked List to a Dynamic Array... Dynamic arrays aren't something im strong with. //********bintree.h******** #ifndef BINTREE_H #define BINTREE_H #include <cstdlib> // Provides NULL and size_t
4
3781
by: Chris Goller | last post by:
Imagine a cross platform library. A particular object wraps up operating system specific functionality and presents it in a uniform manner. Generally, people use ifdefs to change the functionality of a particular piece of code to match that of the native operating system (#ifdef _WINDOWS, etc) I'm wondering if it is possible to use templates to accomplish this same functionality.
10
1619
by: David Soukal | last post by:
Hello, I have an interesting problem that I'm tackling with. I'm sure there must be some obvious solution... I have this big project. It's composed of several *.lib modules. Now, one of the modules uses IJG JPEG library. But, another module needs to use *modified* verzion of the library: the application displays images - for that it uses "normal" jpeg-6b library. However, some functionality is required that modifies the jpeg files as...
19
78845
by: Paul | last post by:
hi, there, for example, char *mystr="##this is##a examp#le"; I want to replace all the "##" in mystr with "****". How can I do this? I checked all the string functions in C, but did not find one.
3
1592
by: Manny Silva | last post by:
Hi, I would like to create a static library that uses and in effect adds to another static library. I could simply add functionality to the existing library, but functionally it doesn't really belong there... that is, the one library is very inspecific. The Library I need to create will be project specific, and I prefer not to have to mix the two... in any case, I tried to create a library that referenced the first library. I added...
1
3568
by: mmacrobert | last post by:
Hi Everyone, I've created a 'C' dll that is accessed via ctypes library containing a bunch of functions. I've successfully been able to use the functions. However, I would like to throw python exceptions from some of them. I throw them using: ::PyErr_SetString(::PyExc_RuntimeError, theErrorString); I crash the console when this function is invoked in the 'C' domain. I
10
1401
by: Anil Gupte | last post by:
In one VB.Net 2003 solution, I have three projects (one in the installer project and not relevant here). However, the other two are the ones where I want to share some commone fucntions. One is a Windows Forms based app and the other is a Windows Service. Is this possible? TIA, -- Anil Gupte www.keeninc.net www.icinema.com
83
4238
by: liketofindoutwhy | last post by:
I am learning more and more Prototype and Script.aculo.us and got the Bungee book... and wonder if I should get some books on jQuery (jQuery in Action, and Learning jQuery) and start learning about it too? Once I saw a website comparing Prototype to Java and jQuery to Ruby... but now that I read more and more about Prototype, it is said that Prototype actually came from Ruby on Rails development and the creator of Prototype created it...
16
3289
by: Xiaoxiao | last post by:
Hi, I got a C library, is there a way to view the public function names in this library so that I can use in my C program? Thanks.
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10435
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10163
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9037
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6779
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.