PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > Making thumbnails 'on the fly'.
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Making thumbnails 'on the fly'.

Réponse
 
LinkBack Outils de la discussion
Vieux 16/02/2008, 11h28   #1
The Natural Philosopher
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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.


  Réponse avec citation
Vieux 16/02/2008, 12h47   #2
Norman Peelman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Making thumbnails 'on the fly'.

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.
>
>


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

--
Norman
Registered Linux user #461062
  Réponse avec citation
Vieux 16/02/2008, 13h35   #3
The Natural Philosopher
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Making thumbnails 'on the fly'.

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.
>>
>>

>
> imagecreatefromstring() 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..

  Réponse avec citation
Vieux 16/02/2008, 15h00   #4
The Natural Philosopher
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Making thumbnails 'on the fly'.

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.
>>
>>

>
> imagecreatefromstring() 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_thumbnail.php?id=%d\"
width=\"100px\">",$product_id);
?>
and send_thumbnail.php itself is..

<?php
$privilege_level=0; // only we an access anything..external users must
match,
include('shoplib.php'); // deals with privilege levels and database
opening..
// include('mimelib.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_query($query);
if(($result>0) && (($rows=mysql_numrows($result)) == 1)) //got some data
{
$content=mysql_result($result,0,'picture');
}
else die();
if ($name="") die();

// now to shrink the picture..
$im=imagecreatefromstring($content);
// get sizes
$width=imagesx($im);
$height=imagesy($im);
// our thumbnails are 100px wide..dont care about the height so scale as
width
$newheight=round(($height*100)/$width);
$newwidth=100;
$thumbnail=imagecreatetruecolor($newwidth,$newheig ht); // make empty new
wotsit.
imagecopyresampled($thumbnail,
$im,0,0,0,0,$newwidth,$newheight,$width,$height);
header("Content-Type: image/jpeg");
imagejpeg( $thumbnail,null,75);
?>
  Réponse avec citation
Vieux 16/02/2008, 16h22   #5
Michael Fesser
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Making thumbnails 'on the fly'.

..oO(The Natural Philosopher)

>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.
>[...]


You should definitely add some caching to store the resized images on
disk (outside the document root) or in the DB as well. Scaling images is
one of the most time-consuming processes. You don't want to do the same
thing over and over again, since this just creates another bottleneck.

Micha
  Réponse avec citation
Vieux 16/02/2008, 16h34   #6
The Natural Philosopher
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Making thumbnails 'on the fly'.

Michael Fesser wrote:
> .oO(The Natural Philosopher)
>
>> 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.
>> [...]

>
> You should definitely add some caching to store the resized images on
> disk (outside the document root) or in the DB as well. Scaling images is
> one of the most time-consuming processes. You don't want to do the same
> thing over and over again, since this just creates another bottleneck.
>
> Micha

Good point, but in this case it not necessary here at this point.

The machine is a small commercial server on the end of an ADSL line
essentially 448Kbps as far as downloading FROM it goes..

If it were to get 1000 hits a day we would be over the moon.
Its does noting else BUT display HTML stuff largely, so has plenty spare
capacity.

The original images are not huge..mostly 480-640 pixels wide...its
purely to display shop style product shots so we don't have a huge
amount of RAM or processing power being taken up either. In any case RAM
is cheap.


The reason to resize was taken because we had an excess of processing
power over bandwidth.

Ecah picture in the list is a separate threaded instance of php/apache
anyway, so its not a huge per prioess load. Just a lot of little
processes. ;-)

  Réponse avec citation
Vieux 16/02/2008, 16h57   #7
Victor Remose
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Making thumbnails 'on the fly'.

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).


  Réponse avec citation
Vieux 16/02/2008, 21h35   #8
The Natural Philosopher
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Making thumbnails 'on the fly'.

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...

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 19h12.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,20334 seconds with 16 queries