By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,826 Members | 1,338 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,826 IT Pros & Developers. It's quick & easy.

creating and presenting an image in php

P: n/a
Maybe this isn't really a PHP problem. But it's possible that PHP has a
good solution for it.

I have a php page which collects some input from the user, constructs an
image, and then displays it to the user. The line of php that does the
actual presentation to the user is
print "<a href='$string'><img src='$string' width=784 height=431
border=0></a>\n";
where $string is something like
'r.pl?ar=7;cl=10'
so the user gets to see a (large) thumbnail, and can then click on it to
see the full-sized version.

(The actual nitty-gritty of the image creation is done in Perl not PHP.
I wrote it before I became more familiar with PHP and learned that PHP
uses the GD library. I could rewrite it into PHP if I have to.)

My problem is that my code calls r.pl twice, to do the same thing: once
when the page is created, and once when the user clicks on the image.
This wastes quite a bit of cpu time on the server, and slows the
response for the user. What I would prefer to do is call r.pl once, put
the resulting image in some kind of temporary session-specific file on
the server (or in its memory), and then use this temporary thing twice,
in place of $string above. Is this somehow possible?

Nick
--
Nick Wedd ni**@maproom.co.uk
Jan 30 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Nick Wedd wrote:
Maybe this isn't really a PHP problem. But it's possible that PHP has a
good solution for it.

I have a php page which collects some input from the user, constructs an
image, and then displays it to the user. The line of php that does the
actual presentation to the user is
print "<a href='$string'><img src='$string' width=784 height=431
border=0></a>\n";
where $string is something like
'r.pl?ar=7;cl=10'
so the user gets to see a (large) thumbnail, and can then click on it to
see the full-sized version.

(The actual nitty-gritty of the image creation is done in Perl not PHP.
I wrote it before I became more familiar with PHP and learned that PHP
uses the GD library. I could rewrite it into PHP if I have to.)

My problem is that my code calls r.pl twice, to do the same thing: once
when the page is created, and once when the user clicks on the image.
This wastes quite a bit of cpu time on the server, and slows the
response for the user. What I would prefer to do is call r.pl once, put
the resulting image in some kind of temporary session-specific file on
the server (or in its memory), and then use this temporary thing twice,
in place of $string above. Is this somehow possible?

Nick
Yes Nick,

Excactly as you described it it could be done.
Just search for image (in the functionsearch) at www.php.net and you'll find
plenty examples.
http://nl2.php.net/manual/en/ref.image.php
Many imagefunctions have the possibility to safe the image to a path or
serve them directly to the browser.
If you run into problems, just come back here.

Good luck,

Regards,
Erwin Moller
Jan 30 '07 #2

P: n/a
In message <45*********************@news.xs4all.nl>, Erwin Moller
<si******************************************@spam yourself.comwrites
>Excactly as you described it it could be done.
Just search for image (in the functionsearch) at www.php.net and you'll find
plenty examples.
http://nl2.php.net/manual/en/ref.image.php
Many imagefunctions have the possibility to safe the image to a path or
serve them directly to the browser.
If you run into problems, just come back here.
I find that I can do all the image-processing stuff, e.g.
<?php
$im = imagecreatefrompng("i/sea.png");
// many image-processing commands
imagepng($im, "foo.png");
?>
<a href='foo.png'><img src='foo.png' width=80 height=60></a>

What I still don't know is how to use a temporary file, that will go
away when the user leaves the page, to store either the image or
header+image.

Nick
--
Nick Wedd ni**@maproom.co.uk
Jan 30 '07 #3

P: n/a
Nick Wedd wrote:
In message <45*********************@news.xs4all.nl>, Erwin Moller
<si******************************************@spam yourself.comwrites
>>Excactly as you described it it could be done.
Just search for image (in the functionsearch) at www.php.net and you'll
find plenty examples.
http://nl2.php.net/manual/en/ref.image.php
Many imagefunctions have the possibility to safe the image to a path or
serve them directly to the browser.
If you run into problems, just come back here.

I find that I can do all the image-processing stuff, e.g.
<?php
$im = imagecreatefrompng("i/sea.png");
// many image-processing commands
imagepng($im, "foo.png");
?>
Ok, good.
<a href='foo.png'><img src='foo.png' width=80 height=60></a>

What I still don't know is how to use a temporary file, that will go
away when the user leaves the page, to store either the image or
header+image.
Well, the overhead needed to store temp image files, and the
garbagecollection to find them and remove old ones, is probably not worth
your time.
Why not simply recreate it? Are you charged per CPU-cycle? ;-)

But if you want to do it you have several options, depending on what it is
excactly that you want to achieve.
Is each image you create unique for each visitor?
Do you want different visitor to be able to share images?
Or is your image ONLY valid when created as thumbnail, and then again as big
picture? Should some images be deleted, and others not? And what are the
rules?

You could think up some scheme where you store them in a directory, but if
nobody clicks through to the big picture, that directory will soon be
filled with nonsense images. You'll have to make some cronjob to clean that
up based on creationtime.

I would simply go with the doublecreation: your original plan. Clean and
simple.

Regards,
Erwin Moller

>
Nick
Jan 30 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.