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

Creating an image - speed issues

Hello,

I am writing a gallery script and use imagecreatefromjpeg and fpassthru
to output images without any change to them (i.e., no thumbnail
creation etc. - just deliver the image via the php script). However I
note that the image creation is quite slow - the user can see that the
image is created line-by-line, from top to bottom.

Most likely this speed issue comes from PHP, since PHP is simply slower
than C etc.

However, if I use a "professional" script like e.g. phpThumb, I notice
that the image display is much, much faster - almost as if I had the
image displayed directly.

What can I do to make my images faster? If there's nothing (simple)
that I can do, is there at least a way to make the images as
progressive JPGs, i.e. they don't build up from top to bottom
line-by-line, but the image starts as a blurry image and gets sharper
with time?

Thanks!
Alex

Oct 6 '06 #1
8 3004
On 6 Oct 2006 09:00:14 -0700, "Alexander Fischer" <ha***********@hotmail.com>
wrote:
>I am writing a gallery script and use imagecreatefromjpeg and fpassthru
to output images without any change to them (i.e., no thumbnail
creation etc. - just deliver the image via the php script). However I
note that the image creation is quite slow - the user can see that the
image is created line-by-line, from top to bottom.
Arguably that's the image output rather than creation. The GD library doesn't
stream the image out as it creates it, rather it's all done in memory (which
may take some time, but the browser won't be getting any image data during this
time), then dumped out to the browser in one go.

You'd expect the final output part to be somewhat slower than serving a file
out directly, but no slower than any other large output from PHP - which can
still serve out data quite quickly.

Is all large-ish output from PHP on your server slow? What about compared with
serving static files from the same server?
>Most likely this speed issue comes from PHP, since PHP is simply slower
than C etc.

However, if I use a "professional" script like e.g. phpThumb, I notice
that the image display is much, much faster - almost as if I had the
image displayed directly.
They may well process the image to a temporary location on disk (so it's only
processed once) and then serve it out directly through the webserver, or just
readfile() it (although you mentioned you're using fpassthru which is similar
in purpose).

Looking up phpThumb on Google, it mentions it has the option to process via
ImageMagick, which is less integrated with PHP but can give better performance
for processing photo images (GD is aimed more at generating block graphics
rather than processing photos).
>What can I do to make my images faster? If there's nothing (simple)
that I can do, is there at least a way to make the images as
progressive JPGs, i.e. they don't build up from top to bottom
line-by-line, but the image starts as a blurry image and gets sharper
with time?
The GD library has an interlacing option, which (according to the docs anyway)
for JPEG it actually interprets as using progressive mode - look up
imageinterlace().

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Oct 6 '06 #2
Alexander Fischer wrote:
Hello,

I am writing a gallery script and use imagecreatefromjpeg and fpassthru
to output images without any change to them (i.e., no thumbnail
creation etc. - just deliver the image via the php script). However I
note that the image creation is quite slow - the user can see that the
image is created line-by-line, from top to bottom.

Most likely this speed issue comes from PHP, since PHP is simply slower
than C etc.

However, if I use a "professional" script like e.g. phpThumb, I notice
that the image display is much, much faster - almost as if I had the
image displayed directly.

What can I do to make my images faster? If there's nothing (simple)
that I can do, is there at least a way to make the images as
progressive JPGs, i.e. they don't build up from top to bottom
line-by-line, but the image starts as a blurry image and gets sharper
with time?

Thanks!
Alex
Alex,

Are you trying to resize the image in your html? If so, bad idea. This
will send the entire image file to the browser and display the behavior
you are experiencing. It also unnecessarily inflates the bandwidth
you're using.

"Professional" scripts create a thumbnail and send it instead. The size
difference is quite significant for larger pictures. And even for
smaller images the difference is usually quite noticeable.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Oct 6 '06 #3
Jerry,
thanks for your reply.
Are you trying to resize the image in your html? If so, bad idea. This
will send the entire image file to the browser and display the behavior
you are experiencing. It also unnecessarily inflates the bandwidth
you're using.
No, of course not. When I need a thumbnail, I resample the original
image within PHP. However, I'm having speed issues also and primarily
when I'm simply showing the original-sized (800x600px) image..

Alex

Oct 6 '06 #4
Hi Andy!
You'd expect the final output part to be somewhat slower than serving a file
out directly, but no slower than any other large output from PHP - which can
still serve out data quite quickly.

Is all large-ish output from PHP on your server slow? What about compared with
serving static files from the same server?
I don't think that all PHP output is slow. Well, I don't know - can't
really compare. When I directly serve the image file, i.e. <img
src="picture.jpg">, it's there in an instant. Same when I use phpThumb
<img src=phpThumb.php?src=picture.jpg>. I'm talking about a 800x600
image, so no huge sizes there. When I output it with my PHP code, which
is serving some header data and than fpassthru, it takes about half a
second for the whole image to appear, and it comes line-by-line, which
is noticeable and annoying.
The GD library has an interlacing option, which (according to the docs anyway)
for JPEG it actually interprets as using progressive mode - look up
imageinterlace().
Will do. Any other ideas how I could find out whether my server is too
slow, my code sucks, or whatever else is the problem here?

Thanks,
Alex

Oct 6 '06 #5

Alexander Fischer wrote:
Will do. Any other ideas how I could find out whether my server is too
slow, my code sucks, or whatever else is the problem here?
Actually, now that I tried it again: when I output the image directly
from the server, it has the same - slow - speed the first time it's
loading. When I reload the page, it's there instantly - probably cached
somehow. If I really reload everything by hitting Ctrl-F5, it takes
again the half second or so.

So obviously the server or the connection is slow in itself. But there
is the different caching behavior - the static image gets cached, while
my php-output images get fully reloaded every single time. This is
especially annoying in thumbnail pages, as there first one sees all the
images, and then they flicker through as one by one is being visibly
rebuilt.

Any suggestions on how I could make sure that also my PHP-created
images will get cached the same way as static files?

Thanks,
Alex

Oct 6 '06 #6
Alexander Fischer wrote:
Jerry,
thanks for your reply.

>>Are you trying to resize the image in your html? If so, bad idea. This
will send the entire image file to the browser and display the behavior
you are experiencing. It also unnecessarily inflates the bandwidth
you're using.


No, of course not. When I need a thumbnail, I resample the original
image within PHP. However, I'm having speed issues also and primarily
when I'm simply showing the original-sized (800x600px) image..

Alex
Displaying the 800x600 can be slow - even on a broadband connection.
How large is the file?

And I doubt PHP itself it the problem - unless you're doing something
really strange.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Oct 7 '06 #7
Hi,

Jerry Stuckle wrote:
Displaying the 800x600 can be slow - even on a broadband connection.
ok. Then I can live with that.
How large is the file?
Some 100 kb, on average...
And I doubt PHP itself it the problem - unless you're doing something
really strange.
Well, the only thing that really annoys me is the behavior of the page
in which I display some 30 thumbnails, which I create with this code:

if($showasthumb){
// Content type
header('Content-type: image/jpeg');
// Get new dimensions
list($width, $height) = getimagesize($imgname);
if($width>=$height){$new_width = $mwthumbs_width;$new_height =
$height * $new_width / $width;}else{$new_height =
$mwthumbs_height;$new_width = $width * $new_height / $height;}
// Resample
$image_p = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_p, $im, 0, 0, 0, 0, $new_width,
$new_height, $width, $height);
// Output
imagejpeg($image_p, null, 100);
exit();
When the thumbs page is loaded for the first time, it takes a few
moments to load, ok. Then I view an individual image. Then I click back
in the browser. And now: I instantly get to see the whole page with all
the images on it - probably from the cache. And then the browser starts
to reload image after image, rebuilding them line by line, and this
causes a flickering across the screen which takes around 2-3 seconds.

Would there be a way - e.g., a header information - to tell the browser
that these images do not need to be reloaded every single time?

Thanks,
Alex

Oct 7 '06 #8
On 6 Oct 2006 14:30:37 -0700, "Alexander Fischer" <ha***********@hotmail.com>
wrote:
>Any suggestions on how I could make sure that also my PHP-created
images will get cached the same way as static files?
There are various HTTP headers that control caching, such as Cache-Control and
Expires:

http://www.w3.org/Protocols/rfc2616/...4.html#sec14.9
http://www.w3.org/Protocols/rfc2616/....html#sec14.21

If you've started a PHP session then PHP also sends headers to suppress
caching by default; you can override this though:

http://uk2.php.net/session_cache_limiter

Have a look at the headers being returned for your image (for example with the
Live HTTP Headers extension for Firefox, or Fiddler for Internet Explorer).

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Oct 7 '06 #9

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

Similar topics

4
by: Altramagnus | last post by:
I have 30 - 40 type of different window. For each type I need about 20 instances of the window. When I try to create them, I get "Error creating window handle" My guess is there is a maximum...
1
by: Eric Sasser | last post by:
I'm searching for anyone that has tried working with creating containersin shared memory using the April 2003 article by Grum Ketema in C/C++ UserJournal. I have a project up and running but am...
21
by: DraguVaso | last post by:
Hi, I have an inherited DataGrid, that does lots of extra stuff. For exemple drawing a backgroundimage in every cell. The problem is that it's taking too much time (using gdi+), so I want to do...
0
by: wschlichtman | last post by:
I am running into speed issues when attempting to work with larger image files, e.g., 5 M/Pixel photos. I have been experimenting with in-memory working images which are scaled down to a more...
5
by: David Baker | last post by:
Hi all I am very new to ASP.Net. I am trying to create a sniffer for our program. We want our users to click our sniffer and hopefully the sniffer will check their computer against our...
4
by: Dimitrios Charitatos | last post by:
Hello, I suspect that there is a quite straight forward answer to this, but I can't find it... I want to import an image and extract a matrix (or array) from it with elements showing the RGB...
0
by: hardieca | last post by:
Hi, I would like to create an adapter for the image web control to cure a pet peeve of mine. Currently, if I write out: <asp:Image ImageUrl="myPic.jpg" AlternateText="Some text"...
10
by: Enrique Cruiz | last post by:
Hello all, I am currently implementing a fairly simple algorithm. It scans a grayscale image, and computes a pixel's new value as a function of its original value. Two passes are made, first...
1
by: rsteph | last post by:
I've got some product information pages, with images and text, all setup within a table. I'm trying to add a small image in the upper right hand corner of the content div (where all the important...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.