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

creating and presenting an image in php

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
3 1440
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Arcnet | last post by:
Using MemoryStream I Have a problem to create a new Image from byte array that originaly was created from an older image (Everything is being preformed in the same Thread) //Get Image...
2
by: asad | last post by:
Hello friends, how ru all, i have some problem about saving created thumbnail, following is the code i use for creating thumbnail but thumbnail was not saved it is on memory which method is used to...
7
by: Nathan Sokalski | last post by:
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving,...
4
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. ...
8
by: ctiggerf | last post by:
I was hopeing someone could help me out here. Been stumped on this one all day. This function 1. Checks uploaded files. 2. Creates two resized images from each (a full size, and a...
3
by: tshad | last post by:
oThumbnail.Save is giving me an error: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. theFileName = New FileInfo(strFileName) fileOut =...
1
by: =?Utf-8?B?bXIgcGVhbnV0?= | last post by:
My application requires user interaction with a graphics interface that is changing (data is being collected and plotted). Sometimes the graphics updates are slow and the user is locked out until...
2
by: oswald.harry | last post by:
hi i am reading a set of jpeg files(RGB) and extracts the pixel values as longs.i want to create a 2d array with numof rows=numof images and numof cols=numof pixels in each image.ie each row of...
2
by: djpaul | last post by:
Hello, I have this program and when i want to load pictures it crashes at the form.showdialog()....??? Here it goes: Private Sub CmbPath_SelectedIndexChanged(ByVal sender As Object, ByVal e As...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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.