AmitavaCh
asked on
How to enlarge Thumbnail pictures in php?
Hi,
I am working on a Photo Album, where user will be uploaded photos and after review of Moderator, the same will be published for public.
In the moderator view, I am displaying all the uploaded pictures as a Thumbnail and would like to give the option to Moderator to enlarge, before publishing the same.
Can you let me know how to enlarge the pictures on Mouseover or click.
=====
<tr>
<td><input type="checkbox" name="hioddenid<?php echo $i; ?>" value="<?php echo $row['id']; ?>" /></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><img src="images/<?php echo $row['picture'];?>" height="80" width="100"/></td>
<input type="hidden" name="image<?php echo $i; ?>" value="<?php echo $row['picture'];?>" />
</tr>
====
The entire code is attached as a file.
Thank you for your help.
Regards,
imageview.php
I am working on a Photo Album, where user will be uploaded photos and after review of Moderator, the same will be published for public.
In the moderator view, I am displaying all the uploaded pictures as a Thumbnail and would like to give the option to Moderator to enlarge, before publishing the same.
Can you let me know how to enlarge the pictures on Mouseover or click.
=====
<tr>
<td><input type="checkbox" name="hioddenid<?php echo $i; ?>" value="<?php echo $row['id']; ?>" /></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><img src="images/<?php echo $row['picture'];?>" height="80" width="100"/></td>
<input type="hidden" name="image<?php echo $i; ?>" value="<?php echo $row['picture'];?>" />
</tr>
====
The entire code is attached as a file.
Thank you for your help.
Regards,
imageview.php
Here is the code, posted in the code snippet. It is a technically incompetent piece of code and probably should be discarded for obsolescence and security reasons. But that aside, you do not want to enlarge a thumbnail if there is any way to avoid it. Instead you want to work from the original image. The thumbnail has lost some of the image information and no amount of guesswork is likely to recover the lost data.
I would design this application as follows:
1. Upload the image and move it to an "originals" folder
2. Prepare the (thumbnail) view for the moderator
3. Upon the moderator's signal, go back to the "originals" version of the image for any further processing before public display.
I would design this application as follows:
1. Upload the image and move it to an "originals" folder
2. Prepare the (thumbnail) view for the moderator
3. Upon the moderator's signal, go back to the "originals" version of the image for any further processing before public display.
<?
session_start();
if(!session_is_registered(myusername)){
header("location:mediatorlogin.php");
session_destroy();
}
?>
<?php
include 'config.php';
error_reporting(E_ALL ^ E_NOTICE);
$select = mysql_query("SELECT * from myimages");
if(isset($_POST['submit']))
{
for($i=1;$i<=$_POST['hidden'];$i++)
{
$query2 = mysql_query("SELECT picture from myimages WHERE id = ' ".$_POST["hioddenid$i"]." ' ");
while($file = mysql_fetch_array($query2))
{
$unlink = unlink('images/'.$file['picture']);
$unlink1 = unlink('images/'.$file['picture'].'.txt');
if($unlink)
{
$query1 = mysql_query("DELETE from myimages WHERE id = ' ".$_POST["hioddenid$i"]." ' ");
//echo 'Deleted , You Will be Redirect';
//header("refresh : 3 imageview.php");
header('Location: imageview.php');
}
else
{
echo 'Not deleted';
}
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
history.forward();
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>View Images</title>
</head>
<body>
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
<table align="center" cellspacing="15">
<tr><a href="MediatorLogout.php">Logout</a></tr>
<tr>
<th align="left">Action</th>
<th align="left">Uploder Name</th>
<th align="left">Caption</th>
<th align="left">Picture</th>
</tr>
<?php
$i = 0;
while($row = mysql_fetch_array($select))
{
$i = $i + 1;
?>
<tr>
<td><input type="checkbox" name="hioddenid<?php echo $i; ?>" value="<?php echo $row['id']; ?>" /></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><img src="images/<?php echo $row['picture'];?>" height="80" width="100"/></td>
<input type="hidden" name="image<?php echo $i; ?>" value="<?php echo $row['picture'];?>" />
</tr>
<?php
}
?>
<tr>
<input type="hidden" name="hidden" value="<?php echo $i; ?>" />
<td colspan="3" align="center"><input type="submit" name="submit" value="Delete"/></td>
</tr>
</table>
</form>
</body>
</html>
<?
/*
//to create text file for description
$text1=$_POST['email'];
$filename = $_FILES["file"]["name"].".txt" ;
$Content = $text1;
//echo "open";
$handle = fopen("images/" .$filename, 'x+');
//echo " write";
fwrite($handle, $Content);
//echo " close";
fclose($handle);
*/
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you
You can upload the file and save one version to a directory called large, and reduce the size to your desired dimensions and save it to a directory called thumbs.
Ray_Paseur provided a great script for doing just that.
It is great and eliminates image degradation as you try to enlarge an existing image.