473,804 Members | 3,958 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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=1 0'
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 1458
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=1 0'
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************ *************** *************** @spamyourself.c omwrites
>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 = imagecreatefrom png("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************ *************** *************** @spamyourself.c omwrites
>>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 = imagecreatefrom png("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
garbagecollecti on 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
5577
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 From File byte arr;
2
1929
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 store created thumbnail in to hard disk <%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %> <%@ Import Namespace="System.Drawing.Imaging"%>
7
2322
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, the other in which I close the FileStream afterwards, although both return the same error. Here are the two versions of the code and the errors they each return (NOTE: I rebooted immediately before running each of these versions so that I knew they...
4
2761
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. It should put a blue and yellow box on the page with "This is a test" as part of the picture. But what I get is a broken Gif. The other problem is that I can't view the source???? The view source is disabled for this page. What causes this?
8
2833
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 thumbnail). 3. Returns an array with a bool (false if the upload failed), and an error message.
3
1679
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 = fileIn.Substring(0,fileIn.LastIndexOf(".")) & session("User").CompanyID & fileIn.Substring(fileIn.LastIndexOf(".")) pathFileOut = Server.MapPath("\Uploads") & "\" & fileIn.Substring(0,fileIn.LastIndexOf(".")) & "Temp" &
1
1076
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 completion for tasks like scaling and reading the cursor and all that. I would like to do all of the drawing and associated calculations in a background worker then have the updated information flash onto the form holding the graphics forthwith....
2
2980
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 the 2d array will represent an image. I managed to get the imagedata using jpeg library of cygwin and it stores the rgb values in array pointed to by unsigned char *image .and i am able to get the rgb values for each pixel and pack them into a
2
1552
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 System.EventArgs) Handles CmbPath.SelectedIndexChanged Dim Table As DataTable Dim i As Integer Dim ThumbSize As Integer = 160
0
9585
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
10586
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
10323
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
10082
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9161
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...
0
5525
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
5658
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
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 we have to send another system
3
2997
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.