Announcement

  •  » Extensions
  •  » Automatic thumbnail generation (without ImageMagick)

#1 2004-11-28 13:15:02

Sephi
Former Piwigo Team
Suisse
2004-11-28
430

Automatic thumbnail generation (without ImageMagick)

I made this because I wanted an automatic thumbnail generation, without using an external program and uploading the thumbnails myself.
Could be useful if the server doesn't have ImageMagick.

Open admin/update.php, in the function "insert_local_image" find :

Code:

 // if we found a thumnbnail corresponding to our picture...
      if ( $tn_ext != '' )

Before this, add :

Code:

  // Thumbnail generation
  if(!file_exists($dir . 'thumbnail'))
    @mkdir($dir . 'thumbnail');
  $ratio = 100;
  $size = getimagesize($dir . $unregistered_picture);
  $src = imagecreatefromjpeg($dir . $unregistered_picture);
  $dest = imagecreatetruecolor($ratio, round(($ratio/$size[0])*$size[1]));
  imagecopyresized($dest, $src, 0, 0, 0, 0, $ratio, round(($ratio/$size[0])*$size[1]) , $size[0], $size[1]);   
  imagejpeg($dest,$dir . 'thumbnail/' . $unregistered_picture);

  $tn_ext = get_extension( $unregistered_picture );
  // End thumbnail generation

The ratio is the maximum width of the thumbnails, you can change it of course.
The script will do its work when you'll update the pictures' list.
If you get some bugs with this function, just e-mail me.

Hoping this will be useful to some of you.

Last edited by Sephi (2004-11-28 13:15:54)

Offline

 

#2 2004-12-01 10:56:24

vimages
Member
2004-03-27
2116

Re: Automatic thumbnail generation (without ImageMagick)

Hi, nice Mod, sure...
I think I will try to install it...

but how could we impose a particular size for all thumbnails... ?

for exemple 150pixels maxi as height and wide.. with the originals porportions..of course..

Offline

 

#3 2004-12-01 11:54:43

vimages
Member
2004-03-27
2116

Re: Automatic thumbnail generation (without ImageMagick)

In BSF is not working........

Offline

 

#4 2004-12-01 14:07:19

Sephi
Former Piwigo Team
Suisse
2004-11-28
430

Re: Automatic thumbnail generation (without ImageMagick)

Yep this is because I removed the prefix of the thumbnails in the configuration, so it works on mine.
Choubs, thanks for your correction, I didn't try it but I think it should work.

For the max. height, you can't set it. You just can set the max. width, and the script will adapt the height, keeping the proportions of the picture. You can't precise the height AND width, else the proportions will not be preserved...

Offline

 

#5 2004-12-01 18:57:08

vimages
Member
2004-03-27
2116

Re: Automatic thumbnail generation (without ImageMagick)

whaou !!! super Choubs, I include this mod to my gallery ! It works really fine.....

I will use it when I update my pro-gallery from 1.3.2 to 1.4... I have to many folders and thumbnails are created with photoshop, in 200pixel wide, to heavy.. +or- 25ko...  so, i Will re-create them in 150px with PWG, 4 or 6 ko each, it's faster to display.

the only problem is the bad quality....

thanks..

Offline

 

#6 2004-12-01 23:30:25

Sephi
Former Piwigo Team
Suisse
2004-11-28
430

Re: Automatic thumbnail generation (without ImageMagick)

If you want quality, use ImageMagick. ^_^

Offline

 

#7 2005-01-15 09:42:38

Ramon
Member
2005-01-15
2

Re: Automatic thumbnail generation (without ImageMagick)

Hi who can help me to gett my systeem ready. I want automatic thumbs and i am not a coder who can help or tell me exactly what to do to gett this ready.

Greet Ramon

Offline

 

#8 2005-01-15 11:11:22

Sephi
Former Piwigo Team
Suisse
2004-11-28
430

Re: Automatic thumbnail generation (without ImageMagick)

Hello Ramon,

Sorry to not have answered to your mail, I was pretty busy these days.
So this is what you have to do :

- Open the file admin/update.php
- Find these lines :

Code:

      // 2 cases : the element is a picture or not. Indeed, for a picture
      // thumbnail is mandatory and for non picture element, thumbnail and
      // representative is optionnal
      if (in_array(get_extension($unregistered_element), $conf['picture_ext']))
      {
        // if we found a thumnbnail corresponding to our picture...

(Just do a research for the first one, the following ones should be after it)

- Replace them by these lines :

Code:

// 2 cases : the element is a picture or not. Indeed, for a picture
      // thumbnail is mandatory and for non picture element, thumbnail and
      // representative is optionnal
      if (in_array(get_extension($unregistered_element), $conf['picture_ext']))
      {

    // Thumbnail generation
  if(!file_exists($dir . 'thumbnail'))
    @mkdir($dir . 'thumbnail');
  $ratio = 100;
  $size = getimagesize($dir . $unregistered_element);
  $src = imagecreatefromjpeg($dir . $unregistered_element);
  $dest = imagecreatetruecolor($ratio, round(($ratio/$size[0])*$size[1]));
  imagecopyresized($dest, $src, 0, 0, 0, 0, $ratio, round(($ratio/$size[0])*$size[1]) , $size[0], $size[1]);   
  imagejpeg($dest,$dir . 'thumbnail/' . $conf['prefix_thumbnail'].$unregistered_element);
  $tn_ext = get_extension( $unregistered_element );
    // End thumbnail generation 

        // if we found a thumnbnail corresponding to our picture...

- Save your file.
- Re-upload it on the server.
- That's all folks ! ^^

Offline

 

#9 2005-01-16 12:13:43

Ramon
Member
2005-01-15
2

Re: Automatic thumbnail generation (without ImageMagick)

Hi Sephi,

I have tried to find these lines in the update.php with the crimson editor
i cannot find these lines. i am using the 1.3.4 version
Maybe you can put a piece of the update php with your code in int
so i can see where it belongs.

Greetz Ramon

Offline

 

#10 2005-06-13 15:06:39

Homeless
Guest

Re: Automatic thumbnail generation (without ImageMagick)

Hi. I've installed everything as you tell and it doesnt work. The update.php page works fine but it doesnt create the thumbnail when I upload the new photo. How can it be? I

 

#11 2005-06-17 14:27:56

Yan
Guest

Re: Automatic thumbnail generation (without ImageMagick)

Hi,

I do it but i have some errors : somethings like "getimagesize can't access file xxxxxxxx in xxxxxxxxxx/update.php line 361"

And after, it add my jpeg file in database. So the file exists and is accessible...

Any explication ?

Thx

 

#12 2005-06-27 08:09:34

whoetbe
Member
2005-06-27
0

Re: Automatic thumbnail generation (without ImageMagick)

Bonjour, ma participation à ce MOD :

Pour la version 1.4.1, les variables utilisées ne sont plus les mêmes... d'où quelques erreurs à la génération :

- Ouvrir admin/update.php
- Trouver  :

Code:

// 2 cases : the element is a picture or not. Indeed, for a picture
// thumbnail is mandatory and for non picture element, thumbnail and
// representative is optionnal
if (in_array(get_extension($unregistered_element), $conf['picture_ext']))
{
   // if we found a thumnbnail corresponding to our picture...

- Remplacer par  :

Code:

// 2 cases : the element is a picture or not. Indeed, for a picture
// thumbnail is mandatory and for non picture element, thumbnail and
// representative is optionnal
if (in_array(get_extension($unregistered_element), $conf['picture_ext']))
{
   if(!file_exists($dirname . '/thumbnail'))
   @mkdir($dirname . '/thumbnail');

   $ratio = 100;
   $size = getimagesize($dirname .'/'. $filename);
   $src = imagecreatefromjpeg($dirname .'/'. $filename);
   $dest = imagecreatetruecolor($ratio, round(($ratio/$size[0])*$size[1]));
   imagecopyresized($dest, $src, 0, 0, 0, 0, $ratio, round(($ratio/$size[0])*$size[1]) , $size[0], $size[1]);   
   imagejpeg($dest,$dirname . '/thumbnail/' . $conf['prefix_thumbnail'].$filename);
   $tn_ext = get_extension( $filename );
  // End thumbnail generation 

   // if we found a thumnbnail corresponding to our picture...

- Sauvegarder
- Uploader
- Lancer une synchronisation

Offline

 

#13 2005-06-30 10:13:16

gastoune
Guest

Re: Automatic thumbnail generation (without ImageMagick)

effectivement on perd en qualité mais bon, ca evite pas mal de manips (meme si y a thumbclic)

une remarque :changer $unregistrered_element > $filename

sinon, il faut se mefier, car durant la synchronisation, meme en mode simulation, les vignettes sont créées. (il faudrait rajouter un test)

finalement, il faut aussi se medier des droits d'ecriture sur le repertoire thumbnail. il faudrait rajouter un chmod dans le code php

gastoune

 
  •  » Extensions
  •  » Automatic thumbnail generation (without ImageMagick)

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact