Jump to content

JUST A LITTLE PHP HELP REQUIRED. PHP ALBUM


waqaspuri

Recommended Posts

Please can you help me modify a simple php Album script, the script can be seen at www dot regionaltimes dot com, it places the images without in series, we interested to have to sort by in series, 1.jpg, 2.jpg ... 8.jpg, in other words it works fine for us, but the placement is incorrect that shows the newspaper in the disordered format.

 

<?php

# SETTINGS

$max_width = 200;

$max_height = 200;

$per_page = 10;

 

$page = $_GET['page'];

 

$has_previous = false;

$has_next = false;

 

function getPictures() {

global $page, $per_page, $has_previous, $has_next;

if ( $handle = opendir(".") ) {

$lightbox = rand();

echo '<ul id="pictures">';

 

$count = 0;

$skip = $page * $per_page;

 

if ( $skip != 0 )

$has_previous = true;

 

while ( $count < $skip && ($file = readdir($handle)) !== false ) {

if ( !is_dir($file) && ($type = getPictureType($file)) != '' )

$count++;

}

$count = 0;

while ( $count < $per_page && ($file = readdir($handle)) !== false ) {

if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) {

if ( ! is_dir('thumbs') ) {

mkdir('thumbs');

}

if ( ! file_exists('thumbs/'.$file) ) {

makeThumb( $file, $type );

}

echo '<li><a href="'.$file.'" rel="lightbox['.$lightbox.']">';

echo '<img src="thumbs/'.$file.'" alt="" />';

echo '</a></li>';

$count++;

}

}

echo '</ul>';

 

while ( ($file = readdir($handle)) !== false ) {

if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) {

$has_next = true;

break;

}

}

}

}

 

function getPictureType($file) {

$split = explode('.', $file);

$ext = $split[count($split) - 1];

if ( preg_match('/jpg|jpeg/i', $ext) ) {

return 'jpg';

} else if ( preg_match('/png/i', $ext) ) {

return 'png';

} else if ( preg_match('/gif/i', $ext) ) {

return 'gif';

} else {

return '';

}

}

 

function makeThumb( $file, $type ) {

global $max_width, $max_height;

if ( $type == 'jpg' ) {

$src = imagecreatefromjpeg($file);

} else if ( $type == 'png' ) {

$src = imagecreatefrompng($file);

} else if ( $type == 'gif' ) {

$src = imagecreatefromgif($file);

}

if ( ($oldW = imagesx($src)) < ($oldH = imagesy($src)) ) {

$newW = $oldW * ($max_width / $oldH);

$newH = $max_height;

} else {

$newW = $max_width;

$newH = $oldH * ($max_height / $oldW);

}

$new = imagecreatetruecolor($newW, $newH);

imagecopyresampled($new, $src, 0, 0, 0, 0, $newW, $newH, $oldW, $oldH);

if ( $type == 'jpg' ) {

imagejpeg($new, 'thumbs/'.$file);

} else if ( $type == 'png' ) {

imagepng($new, 'thumbs/'.$file);

} else if ( $type == 'gif' ) {

imagegif($new, 'thumbs/'.$file);

}

imagedestroy($new);

imagedestroy($src);

}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.