By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,639 Members | 3,105 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,639 IT Pros & Developers. It's quick & easy.

maximize images or pictures

P: 9
Hi, what is the trick or codes of maximizing images when the user click the picture. Images/pictures are not saved on the database..

How about if the images are saved on the database..
I hope you can help me in these two scenarios.....
Feb 3 '07 #1
Share this Question
Share on Google+
3 Replies


ronverdonk
Expert 2.5K+
P: 4,258
Hi, what is the trick or codes of maximizing images when the user click the picture. Images/pictures are not saved on the database..

How about if the images are saved on the database..
I hope you can help me in these two scenarios.....
There is no trick involved. Usually you make a small copy of your original picture, called a thumbnail. That thumbnail is then shown on the screen, e.g. as a clickable link in an <a> link. When the user clicks on that link, the original picture is shown.

The following sample takes an image (see comments), makes a thumbnail and show that thumbnail in a clickable link. When you click the thumbnail, the original picture is shown. You can try itt out and adapt to you own wishes. Good luck.[php]<?php
// directory of the image
$dir = "";
// name of the picture
$picname = "pic01.jpg";
// the prefix of the thumbnail name
$prefix = 'thumb_';
// the maximum size of the thumbnail (here 100 px)
$max_dim = 100;
// the queality of the thumbnail (here 90%)
$quality = 90;
// if the thumbnail was clicked, 'show' gives the image name
if (isset($_GET['show'])) {
echo '<img src="'.$_GET['show'].'" border="0">';
exit;
}
// generate the thumbnail image
generate_thumbnail($picname, $max_dim, $quality, $dir, $prefix);
// set thumbnail in a clickable link
echo "<a href='".$_SERVER['PHP_SELF']."?show=$dir$picname'><img src='$dir$prefix$picname'></a>";

// ------------------------------------
// this function creates the thumbnail
// ------------------------------------
function generate_thumbnail($imagefile, $thumb_max_dimension = 100, $quality = 90, $directory = "", $thumb_prefix)
{
$filename_arr = explode(".", basename($imagefile));
$filetype = $filename_arr[1];

if($filetype == "jpg")
$filetype = "jpeg";

if($filetype != "jpeg" && $filetype != "gif" && $filetype != "png")
return false;

$original_size = getimagesize($imagefile);

eval("\$image = imagecreatefrom".$filetype."(\$imagefile);");

if($original_size[0] > $original_size[1])
{
if($original_size[0] > $thumb_max_dimension)
$thumb_width = $thumb_max_dimension;
else
$thumb_width = $original_size[0];
$thumb_height = $original_size[1]*($thumb_width/$original_size[0]);
}
else
{
if($original_size[1] > $thumb_max_dimension)
$thumb_height = $thumb_max_dimension;
else
$thumb_height = $original_size[1];
$thumb_width = $original_size[0]*($thumb_height/$original_size[1]);
}
$thumb = imagecreatetruecolor($thumb_width, $thumb_height);
imagecopyresampled($thumb, $image, 0, 0, 0, 0, $thumb_width, $thumb_height, $original_size[0], $original_size[1]);
imagejpeg($thumb, $directory.$thumb_prefix.basename($imagefile), $quality);
imagedestroy($thumb);
imagedestroy($image);
}
?>[/php]Ronald :cool:
Feb 3 '07 #2

Motoma
Expert 2.5K+
P: 3,235
There is a script called lightbox that does something like that.
You can find it here.
Feb 3 '07 #3

ronverdonk
Expert 2.5K+
P: 4,258
There is a script called lightbox that does something like that.
You can find it here.
Problem with lightboxes is that they are written in JavaScript and not PHP. And how do you get your images out of the database in an easy way?

Also people who have their JS turned off, can't use it.

But i must admit: it look a great tool.

Ronald :cool:
Feb 3 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.