473,503 Members | 2,289 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can GD load an image from another php script?

Hi everybody!!!
I have a script (foo.php) which uses GD to create an image and sends it
to the browser:

<?php
$img = imagecreatefrompng("mypng.png");

/* other stuff */

header("Content-type: image/png");
imagepng($img);

imagedestroy($img);
?>

I also have another php script: goofy.php.
How can I use imagecreatefrompng to load the result of foo.php (without
saving it on the hard disk first)?

I tried with: imagecreatefrompng("foo.php") but doesn't work...
Can anyone help me, please?

I'm sorry for my bad english...

--
Quando noi ignoranti eravamo di più, tutto era più bello...
(A. Celentano)

Per rispondermi in privato:
s e p r a n o(punto)a n t o n i o(chiocciola)l i b e r o(punto)i t
Jan 3 '06 #1
6 2000
Darkbyte [Work] said the following on 03/01/2006 19:57:
Hi everybody!!!
I have a script (foo.php) which uses GD to create an image and sends it
to the browser:

<?php
$img = imagecreatefrompng("mypng.png");

/* other stuff */

header("Content-type: image/png");
imagepng($img);

imagedestroy($img);
?>

I also have another php script: goofy.php.
How can I use imagecreatefrompng to load the result of foo.php (without
saving it on the hard disk first)?

I tried with: imagecreatefrompng("foo.php") but doesn't work...
Can anyone help me, please?


Well, you could do it with the absolute HTTP URL, i.e.:

imagcreatefrompng("http://example.com/blah/foo.php");

(assuming allow_url_fopen is enabled).

However, doing a complete HTTP transaction just to get an image from
yourself is overkill.

A more sensible, programmatic way of doing this is to put the
image-creation stuff from foo.php into a function in an include() file,
and then call it from foo.php and goofy.php.

--
Oli
Jan 3 '06 #2
Darkbyte [Work] wrote:
Hi everybody!!!
I have a script (foo.php) which uses GD to create an image and sends it
to the browser:

<?php
$img = imagecreatefrompng("mypng.png");

/* other stuff */

header("Content-type: image/png");
imagepng($img);

imagedestroy($img);
?>

I also have another php script: goofy.php.
How can I use imagecreatefrompng to load the result of foo.php (without
saving it on the hard disk first)?

I tried with: imagecreatefrompng("foo.php") but doesn't work...
Can anyone help me, please?

Try this:

$img = imagecreatefromstring(file_get_contents("http://.../foo.php"));

However, *do* use http:// in the name so that the function loads the
page and not the text file.
--

- lüpher
---------------------------------------------
"Man sieht nur das, was man weiß" (Goethe)
Jan 3 '06 #3
> Well, you could do it with the absolute HTTP URL, i.e.:

imagcreatefrompng("http://example.com/blah/foo.php");
Oh yes, I already was doing it... I just was looking for another way to
force imagecreatefrompng() to "execute" my script rather then read it...

[cut]
A more sensible, programmatic way of doing this is to put the
image-creation stuff from foo.php into a function in an include() file,
and then call it from foo.php and goofy.php.


Aehm... I'm using my foo.php script in the html code:

<img src="/blah/foo.php?width=320&height=100" border="0" />

Assuming I'm going to put the stuff into a function, and assuming I'm
going to create a php script that just calls that function so I can load
the image directly from html code, how can it help me with
imagecreatefrompng()?
How could I use the function with imagecreatefrompng()?

--
Quando noi ignoranti eravamo di più, tutto era più bello...
(A. Celentano)

Per rispondermi in privato:
s e p r a n o(punto)a n t o n i o(chiocciola)l i b e r o(punto)i t
Jan 4 '06 #4
> Assuming I'm going to put the stuff into a function, and assuming I'm
going to create a php script that just calls that function so I can load
the image directly from html code, how can it help me with
imagecreatefrompng()?
How could I use the function with imagecreatefrompng()?

DONE!!! DONE!!! AUHAUHAUHAUHAUHAUHA LOOOOOOLLLLL :)

function mystuff($width=1, $height=1)
{
$img = imagecreatetruecolor($width, $height);
/* stuff here */
imagepng($img);
}

$img = imagecreatefromstring(mystuff(320, 200));
header("Content-type: image/png");
imagepng($img);
imagedestroy($img);

That's cool!!! :)

Thanks everybodyyyyyyyy!!!
:) :) :) :)

--
Quando noi ignoranti eravamo di più, tutto era più bello...
(A. Celentano)

Per rispondermi in privato:
s e p r a n o(punto)a n t o n i o(chiocciola)l i b e r o(punto)i t
Jan 4 '06 #5
Darkbyte [Work] said the following on 04/01/2006 09:20:
Assuming I'm going to put the stuff into a function, and assuming I'm
going to create a php script that just calls that function so I can
load the image directly from html code, how can it help me with
imagecreatefrompng()?
How could I use the function with imagecreatefrompng()?


DONE!!! DONE!!! AUHAUHAUHAUHAUHAUHA LOOOOOOLLLLL :)

function mystuff($width=1, $height=1)
{
$img = imagecreatetruecolor($width, $height);
/* stuff here */
imagepng($img);
}

$img = imagecreatefromstring(mystuff(320, 200));
header("Content-type: image/png");
imagepng($img);
imagedestroy($img);


What??? This code is nonsensical!

mystuff() uses imagepng() to output an image to the browser, and has no
return value. Therefore you're effectively calling
imagecreatefromstring(NULL), which just throws warnings. This means that
$img == FALSE, so imagepng() and imagedestroy() fail and throw warnings
as well. Comment out the header() line and you'll see what I mean.

The only reason this appears to work is the combination of mystuff()
outputting (*not* returning) PNG data, coupled with the Content-Type header.
--
Oli
Jan 4 '06 #6
> What??? This code is nonsensical!

Ja!!! It's true, but I changed the code to some other:

function create_my_image($w=1, $h=1)
{
$img = @imagecreatetruecolor($w, $h);
if ($img)
{
/* Other stuff here */
}
return $img;
}

and I use it as:

<?php
include("inc/mod_image.php");

if ($my_img = create_my_image(320, 200))
{
/* Other stuff to the image */

header("Content-type: image/png");
imagepng($my_img);

imagedestroy($my_img);
}
?>

This should work better... or shouldn't?

--
When ignorants were more, everything was better...
(A. Celentano)

Per rispondermi in privato:
s e p r a n o(punto)a n t o n i o(chiocciola)l i b e r o(punto)i t
Jan 4 '06 #7

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

Similar topics

1
3093
by: Charlie | last post by:
Hi I am using the following code to create an image viewer for multiple images. var pageImage = document.images; var image = new Image(); var args = GetQuerystring(); //return arguments from...
1
1694
by: Christophe Candas | last post by:
Hye, You will find here under a script which will load a picture in a layer , picture depending on the cursor position. Everything's ok until the line:...
12
6164
by: Sharon | last post by:
I’m wrote a small DLL that used the FreeImage.DLL (that can be found at http://www.codeproject.com/bitmap/graphicsuite.asp). I also wrote a small console application in C++ (unmanaged) that uses...
3
2083
by: jblossom | last post by:
Hello, I'm in a quandary as to how to address a problem. The site in question: http://agapeyoga.com On the left-hand side of the site are image navigation elements that change when clicked...
1
5093
by: jianxin9 | last post by:
Hi, I have an ajax powered tabs box that has a javascript drop-down search menu in the first tab. When I click on another tab, and go back to the first tab I have to refresh the page to get the...
6
10513
by: Seth Illgard | last post by:
Hi, Im writting a custom CMS and everything looks great, except when I see the results in IE. What im trying to do is: *Have an image in a layer (or relative positioned, or just margined). The...
2
3725
elamberdor
by: elamberdor | last post by:
Hi All! Well, i'm modifying a dynamic map, with lat and long datapoints, my problem is it loads in text perfectly onto exact points I specify on the map, ..well now I want to load in...
4
8380
hemantbasva
by: hemantbasva | last post by:
We have designed an aspx page having five ajax tab in it. the data of first four are designed on page whereas for the fifth tab it renders a user control named MYDOMAIN. in the tab container's even...
0
7093
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...
1
7012
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...
0
7468
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
5598
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,...
0
4690
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...
0
3171
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1522
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
402
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.