Forum Moderators: coopster
I have this image hosting script, I've been working on (with help from google, heh)
But there's a few things nagging me.
1) It can not upload .gif images?
2) The thumbnail looks ugly, can I add antialiasing? (antialiasing is the process where the pixels mix when resizing producing smooth lines i.e looks pretty)
3) (This one is not a mandatory request, but would be cool if someone knew how) Add on the generated thumbnails a small "bar" in the buttom (Like 15px heigh)saying: "Click to see full size" or something like that..
3)Do you have any other suggestions idea's to change some details to make this code better?
Also changing the script so it uses less resources but does the same wouldn't hurt either, heh
Here's the code:
<?phpif(isset($_POST['send']))
{if($_POST['send'] == "ok") {
//tilladte filtyper. Tilføj fx. "image/gif"
$allowedTypes = array("image/jpeg", "image/pjpeg", "image/jpg", "image/gif");$maxFileSize = 10240000; //tilladt max-størrelse i bytes
$max_width = 1024000; //Ja, tilladte max. højde
$max_height = 768000; //Tilladte max. bredde//*nix-path til originalfilens endelige placering
$path = $_SERVER['DOCUMENT_ROOT'] . "/";IF($_FILES['img']['size']> 0)
{//Er fil-typen blandt tilladte?
IF (in_array($_FILES['img']['type'],$allowedTypes))
{//Er fil-størrelsen under max. tilladte?
IF ($_FILES['img']['size'] <= $maxFileSize)
{//Find billedets størrelse
$size = getimagesize($_FILES['img']['tmp_name']);//Filen er ikke for bred
if($size[0] < $max_width)
{//Filen er ikke for høj
if($size[1] < $max_height)
{//Læseligt tidsstempel - tilføjes senere filnavn og giver derved et unikt filnavn
$tid = date("His_dmy", time());//Udregn skaleringsforholdet på thumb, her skal 100 rettes til den ønskede bredde
$new_w = 125;
$division = $size[0] / 100;
$new_h = $size[1] / $division;//Lav et nyt billede så vi kan komme igang
$dst_img=ImageCreateTrueColor($new_w,$new_h);$src_img=ImageCreateFromJpeg($_FILES['img']['tmp_name']);
//Smid noget indhold i, og resize
ImageCopyResized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,ImageSX($src_img),ImageSY($src_img));//*nix-path til thumbfilens endelige placering
$filename2 = "thumbs/" . $img=$tid.$_FILES['img']['name'];//Udfør det hele
//echo "dst_img=".$dst_img."<br>";
//echo "filnavn2=".$filename2."<br>";
ImageJpeg($dst_img, $filename2);//Flyt filen fra tmp til endelig placering
move_uploaded_file($_FILES['img']['tmp_name'], $path.$tid.$_FILES['img']['name']) or die("There has happend an mistake!");
echo "<center><br>Thumbnail Code: <b><input type='text' class='textfield' onClick='highlight(this);' style='width: 400px' size='70' value='['name']."][MySite.com] ' /><br></b>
Signature Code / Show Image: <b><input type='text' class='textfield' onClick='highlight(this);' style='width: 400px' size='70' value='' /><br></b>
Direct Link To Image: <b><input type='text' class='textfield' onClick='highlight(this);' style='width: 400px' size='70' value='http://MySite.com/".$tid.$_FILES['img']['name']." ' /> (<a href='http://MySite.com/".$tid.$_FILES['img']['name']." '>check</a>)</b><br><br><b>Preview:</b><p><a href='/".$tid.$_FILES['img']['name']."'><img border='0' src='".$filename2."'></a></center><br></p>";
if(isset($_POST['tekst']))
{
echo $_POST['tekst'];
}
}ELSE
{
//Fejlmedl. hvis fil over max. tilladt
$fejl = "Billede ikke sat ind: Filen er for høj!";
}
}ELSE
{
//Fejlmedl. hvis fil over max. tilladt
$fejl = "Billede ikke sat ind: Filen er for bred!";
}
}ELSE
{
//Fejlmedl. hvis fil over max. tilladt
$fejl = "The file is too big!";
}
}
ELSE
{
//Fejlmedl. hvis fil-format ikke tilladt
$fejl = "Wrong File! We only allow: .jpg .gif and .png!";
}
}}
}
if(isset($fejl))
{echo $fejl;
}
?>
Some versions of the GD library don`t support the .gif format due to some copyright problems they had. I believe the latest version does however, so check their website for more information:
[boutell.com...]
Also you are using the ImageCreateFromJpeg() function which is for JPG`s only.
dc
I'm sorry I'm way to new to this php..
I've logged on the site you gave and downloaded the file..
I can't make any sense from it.
I appreciate that your trying to make me do this on my own and learn from it, but the problem is, from where my knowledge is on php, and how much knowledge I need to understand that file is just a way too big gab..
and I really did like this fixed/changed in a soon matter of time..
That means you need to add support for whatever operations you want to do. This means one of the following
- a recent version of PHP (which by default includes a recent version of the GD library).
- ImageMagick
- NetPBM
If you have sufficient privileges to run binaries on your server, you can install either of the last two yourself. Both are excellent packages from what I hear, but I've only used GD and ImageMagick myself. In any case, I find ImageMagick much simpler for manipulating photos that GD.
Good luck
Finnaly someone understood my crytish way of explaining, LOL.
Anyway, I tried adding your code and it worked! (but even thoguht it worked it said some errors on the top of the document.)
[edited by: ergophobe at 4:07 pm (utc) on Aug. 17, 2005]
[edit reason] code dump, do my homework request snipped. Please read the forum charter [/edit]