Visualizzazione risultati 1 fino 3 di 3

Discussione: Resize delle immagini

  1. #1
    Guest

    Predefinito

    A partire da dei file gif o jpeg ho bisogno di crearne degli altri ridimensionati e salvarli in una cartella.

  2. #2
    Guest

  3. #3
    Guest

    Predefinito

    If you ever want to resize a picture (maybe in order to create a thumbnail), this small function
    should help you. It also gives you an idea of how some of the basic image functions of PHP can be
    used.
    /* 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)
    {

    /* Get the dimensions of the source picture */
    $picsize=getimagesize("$sourcefile");
    $source_x = $picsize[0];
    $source_y = $picsize[1];
    $source_id = imageCreateFromJPEG("$sourcefile");
    /* 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 */

    imagejpeg ($target_id,"$targetfile",$jpegqual);
    return true;
    }

Regole di scrittura

  • Non puoi creare nuove discussioni
  • Non puoi rispondere ai messaggi
  • Non puoi inserire allegati.
  • Non puoi modificare i tuoi messaggi
  •