473,946 Members | 1,236 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Making thumbnails 'on the fly'.

I have a databse containing amongst other things many images stored as
BLOBS.

When listing, currently I download all the images full size and let he
browser do the reduction to thumbnails.

It's getting a little slow on long lists.

Is there anyway to take the data and scale it down on the fly to a
smaller image? I have plenty of processor power, just not much bandwidth.
The images are a mixture of GIF, JPEG and PNG.
Feb 16 '08 #1
8 2349
The Natural Philosopher wrote:
I have a databse containing amongst other things many images stored as
BLOBS.

When listing, currently I download all the images full size and let he
browser do the reduction to thumbnails.

It's getting a little slow on long lists.

Is there anyway to take the data and scale it down on the fly to a
smaller image? I have plenty of processor power, just not much bandwidth.
The images are a mixture of GIF, JPEG and PNG.

imagecreatefrom string() is your friend. Then just resize to your liking
and output as normal.

--
Norman
Registered Linux user #461062
Feb 16 '08 #2
Norman Peelman wrote:
The Natural Philosopher wrote:
>I have a databse containing amongst other things many images stored as
BLOBS.

When listing, currently I download all the images full size and let he
browser do the reduction to thumbnails.

It's getting a little slow on long lists.

Is there anyway to take the data and scale it down on the fly to a
smaller image? I have plenty of processor power, just not much bandwidth.
The images are a mixture of GIF, JPEG and PNG.


imagecreatefrom string() is your friend. Then just resize to your liking
and output as normal.
Looks good.Any special libraries needed? having hell trying to install
imagemagick..

Feb 16 '08 #3
Norman Peelman wrote:
The Natural Philosopher wrote:
>I have a databse containing amongst other things many images stored as
BLOBS.

When listing, currently I download all the images full size and let he
browser do the reduction to thumbnails.

It's getting a little slow on long lists.

Is there anyway to take the data and scale it down on the fly to a
smaller image? I have plenty of processor power, just not much bandwidth.
The images are a mixture of GIF, JPEG and PNG.


imagecreatefrom string() is your friend. Then just resize to your liking
and output as normal.
Well MANY thanks..

After struggling to get Gdlib on one machine..it was magically on the
other..I didn't realise that php5-gd was an extra debian package

the final send-thumbnail.php is, with obvious inclides to access
databases etc, as follows.

It sends a 100PX wide picture of anything it understands in the
database: speed is about ten times greater than with the original mostly
480px wide images.

The actual code that calls the sub file is
<?
printf("<IMG src=\"send_thum bnail.php?id=%d \"
width=\"100px\" >",$product_id) ;
?>
and send_thumbnail. php itself is..

<?php
$privilege_leve l=0; // only we an access anything..exter nal users must
match,
include('shopli b.php'); // deals with privilege levels and database
opening..
// include('mimeli b.php'); //Always use JPEG now!!
open_database() ; // ready to check
$id=$_GET['id'];
$query="select picture from product where id='".$id."'";
//echo $query;
$result=mysql_q uery($query);
if(($result>0) && (($rows=mysql_n umrows($result) ) == 1)) //got some data
{
$content=mysql_ result($result, 0,'picture');
}
else die();
if ($name="") die();

// now to shrink the picture..
$im=imagecreate fromstring($con tent);
// get sizes
$width=imagesx( $im);
$height=imagesy ($im);
// our thumbnails are 100px wide..dont care about the height so scale as
width
$newheight=roun d(($height*100)/$width);
$newwidth=100;
$thumbnail=imag ecreatetruecolo r($newwidth,$ne wheight); // make empty new
wotsit.
imagecopyresamp led($thumbnail,
$im,0,0,0,0,$ne wwidth,$newheig ht,$width,$heig ht);
header("Content-Type: image/jpeg");
imagejpeg( $thumbnail,null ,75);
?>
Feb 16 '08 #4
Michael Fesser wrote:
You should definitely add some caching to store the resized images on
disk
....why make them on the fly?
Weather blobs in the database or images on the file system,
the big photos are already there. Adding a few thumbnails won't break
the disk space bank. If you do make them on the fly, then you would
need caching.....but it seems likely you'd run out of ram before
disk space. So making them in advance is still a better solution,
I think. That's what I do (make any missing thumbs at night, from cron).
Feb 16 '08 #5
Victor Remose wrote:
Michael Fesser wrote:
>You should definitely add some caching to store the resized images on
disk

...why make them on the fly?
Weather blobs in the database or images on the file system,
the big photos are already there. Adding a few thumbnails won't break
the disk space bank. If you do make them on the fly, then you would
need caching.....but it seems likely you'd run out of ram before
disk space. So making them in advance is still a better solution,
I think. That's what I do (make any missing thumbs at night, from cron).

Well, if I had thought about it first, I would have made them on the fly
when uploaded and stuffed them in the database..as well..but suh is history.

It's a quick hack to solve a problem *well enough* for now...

Feb 16 '08 #6
FYI, phpThumb support a lot of different formats, caching, and some
other interesting features: http://phpthumb.sourceforge.net/

On Feb 16, 6:28 am, The Natural Philosopher <a...@b.cwrot e:
I have a databse containing amongst other things many images stored as
BLOBS.

When listing, currently I download all the images full size and let he
browser do the reduction to thumbnails.

It's getting a little slow on long lists.

Is there anyway to take the data and scale it down on the fly to a
smaller image? I have plenty of processor power, just not much bandwidth.

The images are a mixture of GIF, JPEG and PNG.
Feb 17 '08 #7
The Natural Philosopher wrote:
Well, if I had thought about it first, I would have made them on the fly
when uploaded and stuffed them in the database..as well..but suh is
history.
Well, why not (now) create a new column in your database, and then write a
quick script to run through the database and create all the thumbnails for
records "WHERE thumbnail IS NULL"? Then run that every night?

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 20 days, 18:15.]

Bottled Water
http://tobyinkster.co.uk/blog/2008/02/18/bottled-water/
Feb 19 '08 #8
Greetings, The Natural Philosopher.
In reply to Your message dated Sunday, February 17, 2008, 00:35:01,
>>You should definitely add some caching to store the resized images on
disk

...why make them on the fly?
Weather blobs in the database or images on the file system,
the big photos are already there. Adding a few thumbnails won't break
the disk space bank. If you do make them on the fly, then you would
need caching.....but it seems likely you'd run out of ram before
disk space. So making them in advance is still a better solution,
I think. That's what I do (make any missing thumbs at night, from cron).

Well, if I had thought about it first, I would have made them on the fly
when uploaded and stuffed them in the database..as well..but suh is history.
It's a quick hack to solve a problem *well enough* for now...
I typically do nothing on the upload, except what is REALLY need to ensure
upload process are done right. Just if I RE-upload image, I go ahead and
delete corresponding thumbnail.
Creating thumbnails, storing them in cache, and display them from cache...
That's separate thing and it's done in a separate file.
So every time image or thumbnail accessed, it being sent to client from disk
only, using plain readfile().

Here is a code sample:

function imagePreview($n ame)
{
$fname = filesFilter($na me);
if(false === $fname)
{
echo '<html><body><h 3>404 No file &quot;'.htmlspe cialchars($name ).'&quot;</h3></body></html>';
}
else
{
if(!file_exists (GALLERY_BASE_D IR."/.preview/{$fname}"))
{
if(!file_exists (GALLERY_BASE_D IR.'/.preview'))
{
mkdir(GALLERY_B ASE_DIR.'/.preview');
}

$img = imagecreatefrom jpeg(GALLERY_BA SE_DIR."/{$fname}");
$sx = imagesx($img);
$sy = imagesy($img);
$dx = GALLERY_PREVIEW _X;
$dy = GALLERY_PREVIEW _Y;
if(($sx $dx) || ($sy $dy))
{
if($sx $sy)
$dy = $dx * $sy / $sx;
else
$dx = $dy * $sx / $sy;
}

imagecopyresamp led($img2 = imagecreatetrue color($dx, $dy), $img,
0, 0, 0, 0,
$dx, $dy, $sx, $sy);
imagejpeg($img2 , GALLERY_BASE_DI R."/.preview/{$fname}", 90);
}
header('Content-type: image/jpeg');
readfile(GALLER Y_BASE_DIR."/.preview/{$fname}");
}
}

GALLERY_BASE_DI R typically protected and/or restricted to only .php files
being accessible.
--
Sincerely Yours, AnrDaemon <an*******@free mail.ru>

Feb 19 '08 #9

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

Similar topics

4
7344
by: Gregory | last post by:
Hello, I've managed to build two web pages, one that can display images with associated text data in a table, and one that can resize and display images without the text. I'd like to resize the images as I go, without writing them to disk on the server. Do I need to prepare all of the resized images before I display the data from the select (which is put into an array by php). How can I display a resized image in a table, without writing...
2
3714
by: Johan | last post by:
Hi, Where to find a php script to upload jpg files and make thumbnails of the jpg files ? Johan
6
3411
by: shank | last post by:
Is it possible to create thumbnails on-the-fly in ASP? I'm aware of ASPImage, but that appears to create actual files. I want to know if I can make 300 x 300 pixel artwork, and have ASP generate any size I prefer. Maybe I want 50 pixel on this page and 92 pixel on another. I realize I can set the height and width, but I want to actually decrease the download size also. I don't want to recreate a new file for every size. Is this possible? ...
1
2384
by: Espen Evje | last post by:
Hi, I am trying to present the images in a folder as thumbnails in a dynamically created asp:table. I however do not want to save the thumbnails to disk, only show the images in this folder as thumbnails and then forget about them. I've seen a lot of samples using a datagrid/list and automatically bind thumbnails to these controls, but it does not meet my requirements. I've also seen a sample where the thumbnail of one image is...
3
1371
by: Chris D | last post by:
I'm doing some work with submitting graphics via ASP.net page to SQL 2000 server using VB. I know how to get a graphic into the database from a filefield control. I also know how to pull it out of the database and thumbnail it on the fly. Creating thumbnail on the fly seems extremely inefficient to me as this has to be done every time the image is requested. What I want to do is get the image from the filefield control, thumbnail it...
8
3230
by: Fabricio Sperandio | last post by:
Hi everyone, I am trying to generate some thumbnails using System.Drawing.Image Class. Actually the GetThumnailImage method. The question is: How can I get a better thumbnail picture? I mean, when the original size is big, for example, 800x600 and I generate a small picture (160x120) the quality is terrible for a jpeg and even orse for a gif. How can I get some better images? There is another class? There is some resolution propertie I...
6
4772
by: Rich | last post by:
Hello, I want to simulate the dynamic thumbnail display of Windows Explorer (winxp) on a form or pannel container. If I place a picture box on my container form/pannel and dimension it to the size of a thumbnail and set the sizemode to Stretch -- I get one thumbnail. I want to retrieve all the picture files (jpg, bmp) in a directory into an array list and then display this list as thumbnails on my form dynamically. So my question is...
5
2002
by: JJ | last post by:
I have a gallery-like application. (The gallery will be actually presented in Flash, but the management (cms) of the images will be in asp.net. ) My question is, is it ok to create Thumbnail images on the fly by resizing the original sending it to the output stream (i.e. Response.ContentType = "image/jpeg"; Response.BinaryWrite(imageContent) ), or best to actually save the thumbnails to disk. Would this method result in a much slower...
2
2093
by: GK | last post by:
Hi all, I wish to know , how i can create thumbnails automatically using javascripts. It should reduce the size as well as pixel resolution (ie, a 1 mb image of 1280 x 800 px can be reduced to 20kb of 200 X 200 px. Is this possible? If yes, pls let me know. Thanks in advance
0
9981
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
11566
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
11337
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
9886
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...
1
8253
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7424
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6331
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4533
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3541
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.