22 / 02 / 2017

Usuarios conectados: 4

Cargando documento...



Este Sitio:













Mailing List:

Suscríbete a la lista de correo, No practico spamming y ofrece algunas ventajas.

Pulsa aquí para saber más y suscribirte.



Tecnorama >Dreamweaver Extensions


PHP Advanced Random Thumbnails

Versión para imprimir | Translate this page

With this extension you can create and display a thumbnail for a random image from a selected folder.

The extension contains 2 Server Behaviors, accessible at Server Behaviors' panel->Tecnorama->Advanced Random Thumbnails:

1.- "Primary Random Thumbnail" Use this Server Behavior to add the first thumbnail. Besides, you will be able to set the general properties that will apply to all the thumbnails. You should use it only once per page

2.- "Dependant Random Thumbnails": Use this Server Behavior if you want to add more thumbnails to your document.

FAQ's Section:

Read them carefully: They will you show you some guidelines about the use and limitations of the extension.

Q.- Can I add more than one thumbnail to the same page?

Yes: to add more thumbnails to the page, use the "Dependant Random Thumbnail" Server Behavior instead of the "Primary Random Thumbnail" one, which should be used only the first time. Why?

Some parameters ("Add PopUp" and "Thumbnail Prefix") are shared by all the thumbnails. These params can be modified only in the "Primary" window and won't be available for modification by "dependant" thumbnails.

Use the "Primary" Server Behavior only (and at least) once. You can use the "Dependant" SB's as many times as you like (but remember that your server's resources will be affected)

Q.- Can I include subfolders to browse for images?

Yes. Activate the "Browse Subdirs" checkbox. This option is independent for every thumbnail: You can select images from just one folder for one thumbnail and include subfolders in the next one.

Q.- Can I create thumbnails with different widths from the same image ?

Yes. But it will affect system resources:

When the page is executed, it will check if a thumbnail for that image has already been created and if it has the same dimensions you have set. If it matches, the page will use the thumbnail instead of creating a new one (saving system resources).

However, if you're using more than one thumbnail and they use different dimensions, the page will have to create a new thumbnail and overwrite the old one.

Maybe, next versions will add the feature of storing thumbnails with different dimensions from the same original image.

Q.- Can I put a link to the original image?

Yes: Activate the "Add PopUp JavaScript" checkbox in the "Primary" window. It will write a JavaScript function to open the original image in a popUp window. This feature cannot be modified by "Dependant" thumbnails.

Q.- Everytime the page loads, I get the following error:

Warning: imagejpeg: unable to open ‘your_file_path.jpg' for writing in ‘your_php_file_path’ on line (number)

Make sure that the folders where images are stored have write permissions, so the page can create the generated thumbnails in them. Every thumbnail is created in the same folder where the original image is stored.

Q.- When I activate the "Add PopUp JavaScript" checkbox and test the page, I get the following error:

Warning: fopen("fake_win.htm", "w") - Permission denied in ‘your_php_file_path’ on line (number)

The "Add PopUp JavaScript" feature needs to use an html file to load original images in it. This file is called "fake_win.htm" and should be in the same folder as the php page.

The first time the page is executed it will try to create it. However, if the folder does not have write permissions, an error will be returned.

You've got 2 solutions for this:

1.- Give write permissions to the folder where the php page is located, at least for the first time the page is loaded (the page will only try to create "fake_win.htm" if it doesn't exist). After that, you can revert the folder to its former permissions.

2.- Create an empty file (without html tags or anything in it) called "fake_win.htm" in the same folder where the php page is located.

Q.- Which version of GD do I need?

The extension works both with 1.8.x and 2.0.x versions.

The extension has been successfully tested on:

- W2K/PHP4.2.0/GD1.8

- W2K/PHP4.2.0/GD2.0.8

- Linux/PHP4.3.2/GD2.0.8

Q.- Are gifs supported?

No, only jpeg files (*.jpg, *.jpeg). Due to patent restrictions, GD does not support *.gif files.

Q.- Can I choose the width and height of the generated thumbnail?

Only the width. The height will proportionally calculated. This has been done on purpose to avoid distorted thumbnails (it's a feature, not a bug).

Q.- If I can't choose the height, what is the "Height" texfield for?

It will help you to accomodate the image placeholder in design view, so you can see how thumbnails will suit your design (well, approximately).

Q.- What word should I use as prefix?

Choose a string that will be unique in the image's path. For example:

The prefix: "image" won't work with these paths: "images/img1.jpg" or "img/image3.jpg.

Another good reason to choose a good prefix is that, if you want to change it, you'll have to delete all the thumbnails that are using the old prefix!! You are warned about this.

Q.- I'm using the extension in more than one page: Can I use a different prefix in every page?

You could if every page is using images from different folders, but I encourage you not to do so!!

I'll say it again: choose an original prefix and keep tied to it.

You can see a demo here

Download current version (1.0.0)


Comments? 3, so far. Displaying 1 ->3

1.- cool source ! thanks! I'm gonna try it right now but, Can I add a link to every single image? A different one per each. Thanks agaiN!

Tecnorama says: By default the thumbs can only be linked to the original image. You should edit the generated code to achive that.

2.- Awesome extension! Thank you very much. This is the only script I could find that actually has:
Random thumbnails and Searches subfolders all in one! Very easy to use.

3.- Suggestion: Add external link feature... so I can send people somewhere else based on the PICTURE

| |

Add your Comments

Escribe el código de la imagen superior:


TECNORAMA es simplemente una página personal. No sirve ni de promoción del autor ni cosas por el estilo.
Todos los códigos, textos y tutoriales son de libre uso mientras se mencione al autor (no es mucho pedir)
Este sitio es compatible con IE6/NS6/Mozilla1.0
Para contactar, puedes enviarme un e-mail a tecnorama@hotmail.com