Code solutions to PHP, JS, CSSCode source PHP, JS, CSS

Spread your code soluces to the world

Love me
Solucior » PHP » Simple image gallery PHP

Simple image gallery PHP

06/01/2011 by Dux   -   3.8/5 (9 ratings)

The following code is an image gallery script in PHP as easy as possible.
A single file of a few lines of code is sufficient to list the images, create thumbnails and display them.

Copy the entire code into a PHP file. Name it as you wish and drop it in a directory containing images. For reasons of simplicity, this code has no error handling. With you to define it, particularly before creating the thumbnail.

Example : Gallery demonstration

source code

= $_GET['img'];

if (
$img == "") {
// Display Thumbnails
$dir = opendir('.');
   while (
$file = readdir($dir)) if (strpos(mime_content_type($file), 'image') !== false)
'<a href="/'.$file.'" style="display:block; float: left; margin: 2px; width:150px; height:150px; background:url('.$_SERVER['PHP_SELF'].'?img='.$file.') center center no-repeat"></a> ';
} else {
$type = substr(mime_content_type($img), 6, 10);
   eval (
"\$igd = imagecreatefrom".$type."(\$img);");
// Resize
list($x,$y) = getimagesize($img);
   if (
$y > $x) { $nx = 150; $ny = $y / ($x/$nx); } else { $ny = 150; $nx = $x / ($y/$ny); }
$isend = imagecreatetruecolor($nx,$ny);
imagecopyresampled($isend, $igd, 0,0, 0,0, $nx,$ny, $x,$y);
// Send
header('Content-Type: image/'.$type);

Rate this code     |     Copied : 85x

Comments for Simple image gallery PHP

Dux     05/08/2012 02:32
Alexandre, ce doit être un warning, règle ton serveur pour la diffusion. Tu dois être en mode error warning de développement.
Alexandre     05/05/2012 14:53
J'ai une erreur à la première ligne :
Undefined index: img

Que faire ?
Joseph     02/03/2012 02:26

How could I set the code to pull from a specific folder?

Thanks in advance

venkat     09/15/2011 07:23
hi nice code
Add a comment Nickname

Javascript Image magnification
Isolate a color
Extract images from a page
Horizontal scroll div with javascript
Dynamic image resizing according to location
Javascript opacity
Adjust the rate of image colors
Simple image gallery PHP
Automatically adjust brightness contrast of an image
Zoom with CSS3