Picture Gallery which rezises images

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Martin Brunner

    Picture Gallery which rezises images

    Hello!

    I tested several picture galleries now but I didn't find anyone I like.

    It should be very simple (just login and upload) but it should be able
    to rezise pictures. You specify a value for the max height and max width
    and depending if the hight or width is more the picture will be rezised
    so that it fits into the gallery thumnails even if it was taken 90°
    rotated.

    Is there such a script available somewhere?
  • Geoff Berrow

    #2
    Re: Picture Gallery which rezises images

    I noticed that Message-ID:
    <42e7b97e$0$145 50$79720d31@new sreader.inode.a t> from Martin Brunner
    contained the following:
    [color=blue]
    >It should be very simple (just login and upload) but it should be able
    >to rezise pictures. You specify a value for the max height and max width
    >and depending if the hight or width is more the picture will be rezised
    >so that it fits into the gallery thumnails even if it was taken 90°
    >rotated.
    >
    >Is there such a script available somewhere?[/color]

    Not a gallery script, but my upload script does what you want

    <?php

    $path = "images/main/";
    $thumbpath = "images/thumb/";
    $thumbnail_widt h=50;
    $mainpath="imag es/main/";
    $main_width=450 ;
    $max_size = 2000000;
    $filename="";
    if (!empty($_FILES['userfile'])) {

    if (is_uploaded_fi le($_FILES['userfile']['tmp_name'])) {

    if ($_FILES['userfile']['size']>$max_size)
    { echo "The file is too big<br>\n"; exit; }

    if($_FILES['userfile']['type']=="image/gif"){
    $createfunction ="imagecreatefr omgif";}
    else{$createfun ction="imagecre atefromjpeg";}

    if (($_FILES['userfile']['type']=="image/gif") ||
    ($_FILES['userfile']['type'])=="image/pjpeg" ||
    ($_FILES['userfile']['type']=="image/jpeg")) {

    //check if file already uploaded
    //if (file_exists($t humbpath ."s_".
    $_FILES['userfile']['name'])) { echo "The file already exists<br>\n";
    exit; }

    //make a copy of original file
    //$res = copy($_FILES['userfile']['tmp_name'], $path .
    //$_FILES['userfile']['name']);

    //create thumbnail image
    $src_img = $createfunction ($_FILES['userfile']['tmp_name']);
    $new_w = $thumbnail_widt h;
    $new_h = imagesy($src_im g)/(imagesx($src_i mg)/$new_w);
    $dst_img = imagecreatetrue color($new_w,$n ew_h);
    imagecopyresamp led($dst_img, $src_img, 0, 0, 0, 0, $new_w,
    $new_h, imagesx($src_im g), imagesy($src_im g));
    imagejpeg($dst_ img, $thumbpath
    .."s_".$_FILE S['userfile']['name'], 100);

    //create big image
    if(imagesx($src _img)>450){
    $new_w = $main_width;
    $new_h = imagesy($src_im g)/(imagesx($src_i mg)/$new_w);
    $dst_img = imagecreatetrue color($new_w,$n ew_h);
    $res=imagecopyr esampled($dst_i mg, $src_img, 0, 0, 0, 0,
    $new_w, $new_h, imagesx($src_im g), imagesy($src_im g));
    imagejpeg($dst_ img, $path ."b_".
    $_FILES['userfile']['name'], 50);
    $notify = "Main image resampled";
    }
    else{
    $res = copy($_FILES['userfile']['tmp_name'], $path
    .."b_".
    $_FILES['userfile']['name']);
    $notify = "Main image not resampled";
    }

    if (!$res) { echo "<h2>Upload failed!</h2><br>\n"; exit;
    }
    else { echo "<h2>Upload sucessful!</h2>\n";
    }

    $filename=$_FIL ES['userfile']['name'];
    printf("<strong >Main :
    </strong>%sb_%s<b r>\n",$path,$fi lename);
    printf("<strong >Thumbnail :
    </strong>%ss_%s<b r>\n",$thumbpat h, $filename);

    echo "Original File Size:
    ".$_FILES['userfile']['size']." bytes<br>\n";
    echo "File Type: ".$_FILES['userfile']['type']."<br>\n";
    echo "$notify.<br>\n ";
    }

    else { echo "<span class=\"indent1 0bold\">Please use a
    ..jpg or a .gif file</span><br>\n"; exit; }

    printf("<span class=\"indent1 0bold\">Image Thumbnail:
    </span><br><br><s pan class=\"indent1 0bold\"><img
    src=\"%ss_%s\"a lt=\"%s\"></span><br>",$thu mbpath,$filenam e,$_POST['alt_text']);
    imagedestroy($s rc_img);
    imagedestroy($d st_img);
    }
    //end of image upload

    //variables for insertion into product table
    $thumb_url="s_" .$filename;
    $main_url="b_". $filename;



    }

    ?>


    --
    Geoff Berrow (put thecat out to email)
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs http://www.ckdog.co.uk/rfdmaker/

    Comment

    • JDS

      #3
      Re: Picture Gallery which rezises images

      On Wed, 27 Jul 2005 18:42:38 +0200, Martin Brunner wrote:
      [color=blue]
      > I tested several picture galleries now but I didn't find anyone I like.[/color]



      --
      JDS | jeffrey@example .invalid
      | http://www.newtnotes.com
      DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

      Comment

      Working...