Forum Moderators: coopster

Message Too Old, No Replies

Update image uploaded script

yhelp fixing a bug and add a thing or 2

         

Snickers

9:20 am on Jul 31, 2005 (gmt 0)

10+ Year Member



Okay... lets see..

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:

<?php

if(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']."] http://MySite.com".$filename2." [MySite.com] ' /><br></b>
Signature Code / Show Image: <b><input type='text' class='textfield' onClick='highlight(this);' style='width: 400px' size='70' value=' http://MySite.com/".$tid.$_FILES['img']['name']." ' /><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;
}
?>


(Don't mind the non-english comments, hehe)

dreamcatcher

5:05 pm on Jul 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Snickers,

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

Snickers

8:35 pm on Jul 31, 2005 (gmt 0)

10+ Year Member



Thanks for responding me...

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..

tkroll

8:31 am on Aug 1, 2005 (gmt 0)

10+ Year Member



No need to reinvent the wheel. Check out phpThumb on sourceforge. Pass your image through it upon saving. It's a great tool.

Snickers

10:56 am on Aug 1, 2005 (gmt 0)

10+ Year Member



But I like my site :(

I just did like to make it accept .gif also..

and antialising.. heh

Snickers

12:53 pm on Aug 3, 2005 (gmt 0)

10+ Year Member



anyone?

coopster

1:11 pm on Aug 3, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Are you saying you can't upload .gif files, or you can't process them after being uploaded? dreamcatcher is saying that you can probably upload them, but if your server is not configured to handle .gif images after the upload then you need to modify your server configuration to manipulate .gif images.

dreamcatcher

1:39 pm on Aug 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Coop. And sorry Snickers, I seem to have forgot about this post.

First thing is, what version of the GD Library are you using?

Snickers

4:06 pm on Aug 5, 2005 (gmt 0)

10+ Year Member



The newest, I'm 99% sure

Snickers

11:42 am on Aug 7, 2005 (gmt 0)

10+ Year Member



hello?

ergophobe

6:43 pm on Aug 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hello. Still waiting for you to answer coopster's questions.

Snickers

1:12 pm on Aug 8, 2005 (gmt 0)

10+ Year Member



oh sorry.. I misunderstood that part..

How to manipulate the server if it does not accept .gif?

ergophobe

4:22 pm on Aug 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Okay, by "handle" you mean manipulate then, right? In other words, you can upload gif images and display them, but can't do anything else with them.

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

Snickers

4:15 pm on Aug 14, 2005 (gmt 0)

10+ Year Member



I have the 2 first things...

All I know is that my script says error if i try thumbnailing a gif with the script on first page...

How to edit the script so it can do .gif files too?

ergophobe

5:46 pm on Aug 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You only have it set up for jpegs


ImageJpeg($dst_img, $filename2);

If you want to make gifs and pngs, you have to branch (with an if or switch) and use the function for that image type

imagegif()
imagepng()

etc

Snickers

2:12 pm on Aug 15, 2005 (gmt 0)

10+ Year Member



THANK YOU!

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]