imagecopyresampled and imagecopyresized problems

Discussion in 'PHP' started by whirlpool6, Sep 4, 2007.

  1. #1
    hello guys.

    i dont get any image when the following code is run.. i dont know. but i copied them from the php manual itself. is something wrong with my gd library?

    <?php
    // The file you are resizing
    $file = 'http://localhost/try.jpg';
    
    //This will set our output to 45% of the original size
    $size = 0.45;
    
    // This sets it to a .jpg, but you can change this to png or gif
    header('Content-type: image/jpeg');
    
    // Setting the resize parameters
    list($width, $height) = getimagesize($file);
    $modwidth = $width * $size;
    $modheight = $height * $size;
    
    // Creating the Canvas
    $tn= imagecreatetruecolor($modwidth, $modheight);
    $source = imagecreatefromjpeg($file);
    
    // Resizing our image to fit the canvas
    imagecopyresized($tn, $source, 0, 0, 0, 0, $modwidth, $modheight, $width, $height);
    
    // Outputs a jpg image, you could change this to gif or png if needed
    imagejpeg($tn);
    ?>
    Code (markup):
    and

    <?php
    // The file
    $filename = 'D:\public\try.jpg';
    $percent = 0.5;
    
    // Content type
    header('Content-type: image/jpeg');
    
    // Get new dimensions
    list($width, $height) = getimagesize($filename);
    $new_width = $width * $percent;
    $new_height = $height * $percent;
    
    // Resample
    $image_p = imagecreatetruecolor($new_width, $new_height);
    $image = imagecreatefromjpeg($filename);
    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
    
    // Output
    imagejpeg($image_p);
    ?>
    Code (markup):
    pls i need help
     
    whirlpool6, Sep 4, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Try:
    
    $filename = 'D:\\public\\try.jpg';
    
    PHP:
    If that doesn't work either, use your browser's "view page source" and see if you get any PHP errors.


    Oh, and please use
     wrappers instead of [code] wrappers when posting PHP code.
    PHP:
     
    nico_swd, Sep 4, 2007 IP
  3. whirlpool6

    whirlpool6 Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    hello guys.

    everything works perfectly now guys. i can now see the image displayed.

    but i want the image to be placed in an <img> object in html... how can this be done. i just dont know how to do this.

    thanks a lot.
     
    whirlpool6, Sep 4, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    Save the code above as "image.php" or similar, and embed it into your HTML like it was a normal image.

    
    <img src="image.php" />
    
    HTML:
     
    nico_swd, Sep 4, 2007 IP
  5. whirlpool6

    whirlpool6 Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    really? thanks a lot... but wont this kind of keep these in memory? is there a delete something and how?
     
    whirlpool6, Sep 4, 2007 IP