Raptor <me@attbi.com> wrote in message news:<3F**************@attbi.com>...
Lemming wrote: Hi,
[crossposted]
I'm putting together a website for a local estate agent.
One of the things they want to do is upload property
descriptions/prices/etc. plus a picture of the property which is for
sale.
I'd like to generate thumbnails of the pictures automatically either
once the data is uploaded (preferred) or when the relevant page is
delivered to the browser. Server-side scripting will most likely be
done in PHP.
Is this possible?
Lemming
There's a tutorial on creating thumbnails using GD linked to the front
page of phpfreaks.com.
--
I made this one on my own.
<?php
function CheckUpload($filename)
{
$checkjpg = explode('.', $filename);
if($checkjpg[1] == 'jpg' || $checkjpg[1] == 'JPG' || $checkjpg[1] ==
'jpeg' || $checkjpg[1] == 'JPEG')
{
$size = getimagesize("/var/www/domains/factory8.com/r6/pics/uploaded/temp/$filename");
if($size[0] <= '540' && $size[1] <= '600')
{
$size = filesize("/var/www/domains/factory8.com/r6/pics/uploaded/temp/$filename");
if($size <= '102400')
{
if (!file_exists("/var/www/domains/factory8.com/r6/pics/uploaded/$filename"))
{
return TRUE;
}
else
{
die('Filename already exists.');
return FALSE;
}
}
else
{
die('File is greater than 100k');
return FALSE;
}
}
else
{
die('File resolution is to large');
return FALSE;
}
}
die('File must be a jpg, sorry.');
return FALSE;
}
function createThumb($filename,$uid, $extension)
{
$x = '150';
$y = '150';
$location = 'pics/uploaded/thumbnails/'.$uid.'.'.$extension;
$proportain = 1; //0 for no, 1 for yes
if (!$image=getimagesize($filename))
{
return FALSE; //return false if there is no image to create from
or it is not a image
}
else
{
if ($image['2'] == '1')
{
$im = imagecreatefromgif ($filename);
}
else if ($image['2'] == '2')
{
$im = imagecreatefromjpeg ($filename);
}
else
{
return FALSE; // return false if filetype is not of gif or
jpeg
}
if ($proportain == 1)
{
if ($image[0]<$image[1])
{
$x = $y * ($image[0]/$image[1]);
}
else
{
$y = $x / ($image[0]/$image[1]);
}
}
$newim = imagecreatetruecolor($x, $y);
ImageCopyResampled($newim, $im, 0, 0, 0, 0, $x, $y, $image[0],
$image[1]);
imagejpeg($newim, $location);
imagedestroy ($im);
imagedestroy ($newim);
return TRUE;
}
}
?>
--
Uploading file...<br>
<?php
if($file_name !="")
{
copy ("$file", "pics/uploaded/temp/$file_name")
or die("Could not copy file.");
}
else {die("No file specified.");}
?>
Checking file...<br>
<?php
$checkfile = CheckUpload($file_name);
?>
Putting in permanent place...<br>
<?php
copy("$file", "/var/www/domains/factory8.com/r6/pics/uploaded/$file_name");
?>
Creating thumbnail file...<br>
<?php
$fileinfo = explode('.', "$file_name");
$thumbcreated = createThumb("pics/uploaded/$file_name","$fileinfo[0]","$fileinfo[1]");
?>
Adding to the random picture list...<br>
<?php
$dbconn = mysql_connect("localhost", "username", "password");
mysql_select_db("factory8_com");
$addtodb = mysql_query("INSERT INTO bikepics (filename, comment,
owner, ipaddy) VALUES('$file_name', '$comment', '$owner',
'$REMOTE_ADDR')");
mysql_close($dbconn);
?>
<b>Done!</b><br>
<?php
print("
<img src='pics/uploaded/$file_name'><br><img
src='pics/uploaded/thumbnails/$file_name'>
");
?>
--
only bad part, is i forgot to delete the pictures in the temp
directory. :-P