Image Resize script in php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Noorain
    New Member
    • Mar 2008
    • 57

    Image Resize script in php

    Sir
    i want to resize image. Following script working in my local server. But This coding doesn't work in php 2.6.0. please help me
    [code=php]
    <form action="<?php echo $_server['php-self']; ?>" method="post" enctype="multip art/form-data" id="something" class="uniForm" >
    <input name="new_image " id="new_image" size="30" type="file" class="fileUplo ad" />
    <button name="submit" type="submit" class="submitBu tton">Upload/Resize Image</button>
    </form>
    <?php
    if(isset($_POST['submit'])){
    if (isset ($_FILES["new_image"])){
    $imagename = $_FILES["new_image"]["name"];
    $source = $_FILES["new_image"]["tmp_name"];
    $target = "images/".$imagenam e;
    //$prefix = 'small_';
    move_uploaded_f ile($source, $target);

    $imagepath = $imagename;
    $save = "images/sml_" . $imagepath; //This is the new file you saving
    $file = "images/" . $imagepath; //This is the original file

    list($width, $height) = getimagesize($f ile) ;

    $modwidth = 150;

    $diff = $width / $modwidth;

    $modheight = $height / $diff;
    $tn = imagecreatetrue color($modwidth , $modheight) ;
    $image = imagecreatefrom jpeg($file) ;
    imagecopyresamp led($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;

    imagejpeg($tn, $save, 100) ;

    $save = "images/sml_" . $imagepath; //This is the new file you saving
    $file = "images/" . $imagepath; //This is the original file

    list($width, $height) = getimagesize($f ile) ;

    $modwidth = 80;

    $diff = $width / $modwidth;

    $modheight = $height / $diff;
    $tn = imagecreatetrue color($modwidth , $modheight) ;
    $image = imagecreatefrom jpeg($file) ;
    imagecopyresamp led($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;

    imagejpeg($tn, $save, 100) ;
    echo "Large image: <img src='images/".$imagepath."' ><br>";
    echo "Thumbnail: <img src='images/sml_".$imagepat h."'>";

    }
    }
    ?>
    [/code]
    Last edited by Atli; Jun 2 '08, 05:44 PM. Reason: Added [code] tags.
  • Noorain
    New Member
    • Mar 2008
    • 57

    #2
    Originally posted by Noorain
    Sir
    i want to resize image. Following script working in my local server. But This coding doesn't work in php 2.6.0. please help me

    <form action="<?php echo $_server['php-self']; ?>" method="post" enctype="multip art/form-data" id="something" class="uniForm" >
    <input name="new_image " id="new_image" size="30" type="file" class="fileUplo ad" />
    <button name="submit" type="submit" class="submitBu tton">Upload/Resize Image</button>
    </form>
    <?php
    if(isset($_POST['submit'])){
    if (isset ($_FILES["new_image"])){
    $imagename = $_FILES["new_image"]["name"];
    $source = $_FILES["new_image"]["tmp_name"];
    $target = "images/".$imagenam e;
    //$prefix = 'small_';
    move_uploaded_f ile($source, $target);

    $imagepath = $imagename;
    $save = "images/sml_" . $imagepath; //This is the new file you saving
    $file = "images/" . $imagepath; //This is the original file

    list($width, $height) = getimagesize($f ile) ;

    $modwidth = 150;

    $diff = $width / $modwidth;

    $modheight = $height / $diff;
    $tn = imagecreatetrue color($modwidth , $modheight) ;
    $image = imagecreatefrom jpeg($file) ;
    imagecopyresamp led($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;

    imagejpeg($tn, $save, 100) ;

    $save = "images/sml_" . $imagepath; //This is the new file you saving
    $file = "images/" . $imagepath; //This is the original file

    list($width, $height) = getimagesize($f ile) ;

    $modwidth = 80;

    $diff = $width / $modwidth;

    $modheight = $height / $diff;
    $tn = imagecreatetrue color($modwidth , $modheight) ;
    $image = imagecreatefrom jpeg($file) ;
    imagecopyresamp led($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;

    imagejpeg($tn, $save, 100) ;
    echo "Large image: <img src='images/".$imagepath."' ><br>";
    echo "Thumbnail: <img src='images/sml_".$imagepat h."'>";

    }
    }
    ?>

    Sir
    This coding doesn't work in PHP Version 5.1.6 please help me............. .........
    thanks

    Comment

    • hsriat
      Recognized Expert Top Contributor
      • Jan 2008
      • 1653

      #3
      The code as such works for me.

      It seems like GD is not working on you server.
      (link)

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Originally posted by Noorain
        Sir
        This coding doesn't work in PHP Version 5.1.6 please help me............. .........
        thanks
        Hi.
        Simply telling us that it doesn't work is of no use to us.

        How is it supposed to be working?
        How is it really working?
        Are you getting any errors?

        Have you tried to fix this yourself?
        What did you do? Did it change anything?

        Having said that, I would have to agree with Harpreet.
        When a working code that is dealing with image manipulation fails on a new server, the GD extension is most likely just missing.

        P.S.
        Use [code] tags when posting code examples.
        See the Posting Guidelines for more info on that.

        Comment

        Working...