This is a discussion on thumbnails with php within the alt.comp.lang.php forums, part of the PHP Programming Forums category; hy all, i am complety new to GD and i must have a code within 2 days that does the ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
hy all,
i am complety new to GD and i must have a code within 2 days that does the following for me - Upload an image (jpg / png / gif) and save it on the server. - Create an thumbnail of that image with a width and height of 100 - save the thumbnail on the server aswell Can someone please help me on this or could give me a url with a good and quick explanation how to handle GD? Thx in advance, wouter |
|
|||
|
"W. Paulisse" <ihate@spam.nl> schreef in bericht news:3f5589ef$0$49106$e4fe514c@news.xs4all.nl... > > Can someone please help me on this or could give me a url with a good and > quick explanation how to handle GD? > http://www.php.net/gd Read it thouroughly and look ate the examples. I have prepared a quick and dirty demo for you at the following location: http://www.jwscripts.com/playground/thumb.php Just copy this into a local file and adjust the $path variable to suit your environment. JW |
|
|||
|
W. Paulisse wrote:
> hy all, > > i am complety new to GD and i must have a code within 2 days that does the > following for me > > - Upload an image (jpg / png / gif) and save it on the server. > - Create an thumbnail of that image with a width and height of 100 > - save the thumbnail on the server aswell > > Can someone please help me on this or could give me a url with a good and > quick explanation how to handle GD? > > Thx in advance, > wouter I have a script that will do this, but not for free! It's not bad though - it'll handle jpeg and png files, let you resize to an arbitrary size, add a text overlay (if you want), automatically create landscape/ protrait thumbs according to source image size (if wanted), and save the file under a unique name on the server... If you'd like to license it, let me know! Matt |
|
|||
|
W. Paulisse wrote:
> i am complety new to GD and i must have a code within 2 days that > does the following for me > > - Upload an image (jpg / png / gif) and save it on the server. > - Create an thumbnail of that image with a width and height of 100 > - save the thumbnail on the server aswell > > Can someone please help me on this or could give me a url with a good > and quick explanation how to handle GD? Guide on how to create your own in minutes (!?): http://www.sitepoint.com/article/1195/2 |
|
|||
|
"W. Paulisse" <ihate@spam.nl> writes:
> hy all, > > i am complety new to GD and i must have a code within 2 days that does the > following for me > > - Upload an image (jpg / png / gif) and save it on the server. > - Create an thumbnail of that image with a width and height of 100 > - save the thumbnail on the server aswell > > Can someone please help me on this or could give me a url with a good and > quick explanation how to handle GD? > Here are two function that do part of what you want: # Function CreateThumbnail - creates the thumbnail version # of a photo at a fixed size (81 high and correct width) # INPUT - sourcefile name, targetfile name (thumbnail) # OUTPUTS - new file in targetfile location # RETURNS - 0 on success, message otherwise # function CreateThumbnail ($sourcefile, $targetfile) { $desiredY = 81; // Get the dimensions of the source picture $picsize=getimagesize("$sourcefile"); if ($picsize == false) { // failed return("Could not get size on picture $sourcefile"); } $source_x = $picsize[0]; $source_y = $picsize[1]; $ratio = $desiredY / $source_y; $newX = (int) ($ratio * $source_x); $newY = (int) ($ratio * $source_y); if ($msg = ResizeToFile($sourcefile, $newX, $newY, $targetfile)) { return("Resize failed to targetfile: $targetfile ($msg)"); } return(0); } /* Function: resizeToFile resizes a picture and writes it to the harddisk * * $sourcefile = the filename of the picture that is going to be resized * $dest_x = X-Size of the target picture in pixels * $dest_y = Y-Size of the target picture in pixels * $targetfile = The name under which the resized picture will be stored * $jpegqual = The Compression-Rate that is to be used */ function ResizeToFile ($sourcefile, $dest_x, $dest_y, $targetfile, $jpegqual=60) { /* Get the dimensions of the source picture */ $picsize=getimagesize("$sourcefile"); if ($picsize == false) { return("Could not get size on file: $sourcefile\n"); } $source_x = $picsize[0]; $source_y = $picsize[1]; $source_id = imageCreateFromJPEG("$sourcefile"); if (! $source_id) { return("Could not create image from jpeg file: $sourcefile\n"); } /* Create a new image object (not neccessarily true colour) */ $target_id=imagecreatetruecolor($dest_x, $dest_y); /* resize the original picture and copy it into the just created image object. Because of the lack of space I had to wrap the parameters to several lines. I recommend putting them in one line in order keep your code clean and readable */ $target_pic=imagecopyresampled($target_id,$source_ id, 0,0,0,0, $dest_x,$dest_y, $source_x,$source_y); /* Create a jpeg with the quality of "$jpegqual" out of the image object "$target_pic". This will be saved as $targetfile */ $stat = imagejpeg ($target_id,"$targetfile" ,$jpegqual); if (! $stat) { return("Failed to create new image file: $targetfile"); } return 0; } // end function ResizeToFile Hope this helps! -- John __________________________________________________ _________________ John Murtari Software Workshop Inc. jmurtari@thebook.com 315.635-1968(x-211) "TheBook.Com" (TM) http://www.thebook.com/ |
|
|||
|
Thank you for the thumbnail script. It saved me a lot of time. I wil use it (when it's ready) on my website, www.ferme.it. Janwillem Borleffs Wrote: > "W. Paulisse" <ihate@spam.nl> schreef in bericht > news:3f5589ef$0$49106$e4fe514c@news.xs4all.nl... > > > > Can someone please help me on this or could give me a url with a goo > and > > quick explanation how to handle GD? > > > > http://www.php.net/gd > > Read it thouroughly and look ate the examples. I have prepared a quic > and > dirty demo for you at the following location: > > http://www.jwscripts.com/playground/thumb.php > > Just copy this into a local file and adjust the $path variable to sui > your > environment. > > > J -- gianchi6 ----------------------------------------------------------------------- gianchi66's Profile: http://techiegroups.com/member.php?userid=6 View this thread: http://www.techiegroups.com/showthread.php?t=2251 |