Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default thumbnails with php

    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 Guest

  2. Similar Questions and Discussions

    1. Add Dates To Thumbnails
      Hello, I am fairly new to acrobat and have made a long pdf containing weekly reports by managers. Everything is fine except I want the page numbers...
    2. Thumbnails
      What a helpful person cheesefood is.......prat!!! Ifv your thumbnails were saved in an earlier version of PS they may not open so you will need to...
    3. Illustrator thumbnails Win YES and illustrator thumbnails Mac NO?
      Y have 2 different version Adobe Creative Suite one for windows, and one for MacOS X. The probem is: and Illustrator CS Mac the illustrator file...
    4. Illustrator thumbnails Win YES and illustrator thumbnails Mac NO? thumbnails thumbnails Illustr
      Y have 2 different version Adobe Creative Suite one for windows, and one for MacOS X. The probem is: and Illustrator CS Mac the illustrator file...
    5. Hot To: Create thumbnails?
      I am using the Dreamweaver 6.1 Studio on WinXP. This includes version 6 of Fireworks. If I have a huge JPG image, I am trying to figure out how...
  3. #2

    Default Re: thumbnails with php


    "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?
    >
    [url]http://www.php.net/gd[/url]

    Read it thouroughly and look ate the examples. I have prepared a quick and
    dirty demo for you at the following location:

    [url]http://www.jwscripts.com/playground/thumb.php[/url]

    Just copy this into a local file and adjust the $path variable to suit your
    environment.


    JW




    Janwillem Borleffs Guest

  4. #3

    Default Re: thumbnails with php

    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
    matty Guest

  5. #4

    Default Re: thumbnails with php

    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 (!?):
    [url]http://www.sitepoint.com/article/1195/2[/url]


    Martin Tollefsen Guest

  6. #5

    Default Re: thumbnails with php

    "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.
    [email]jmurtari@thebook.com[/email] 315.635-1968(x-211) "TheBook.Com" (TM)
    [url]http://www.thebook.com/[/url]
    John Murtari Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139