Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Jul 2006
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    imagecopyresampled SOLVED!!

    My goal is to resize a picture that has been uploaded so I researched how to do that and found my code at http://us2.php.net/manual/en/functio...yresampled.php it is example two. I uploaded a picture named test.jpg to the same directory as the page and I get this error

    Warning: Cannot modify header information - headers already sent by (output started at /home/istockfi/public_html/spurtstudios/test.php:2) in /home/istockfi/public_html/spurtstudios/test.php on line 12

    followed by a lot of charaters that make no sense to me. You can view the acual page at http://www.spurtstudios.com/test.php

    You can view my GD info at http://www.spurtstudios.com/gd.php
    Can anyone point me in the right direction?

    I have tried several other scripts like this one with no luck so I think it may be a a problem with my host but I don't know what I should do or what to ask them to do.

    Here is my code

    Code:
    <?php
    
    // The file
    $filename = 'test.jpg';
    
    // Set a maximum height and width
    $width = 200;
    $height = 200;
    
    // Content type
    header('Content-type: image/jpeg');
    
    // Get new dimensions
    list($width_orig, $height_orig) = getimagesize($filename);
    
    if ($width && ($width_orig < $height_orig)) {
       $width = ($height / $height_orig) * $width_orig;
    } else {
       $height = ($width / $width_orig) * $height_orig;
    }
    
    // Resample
    $image_p = imagecreatetruecolor($width, $height);
    $image = imagecreatefromjpeg($filename);
    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
    
    // Output
    imagejpeg($image_p, null, 100);
    ?>

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    How are you executing test.php? You don't execute it like a normal PHP file; you insert it in an img tag like this:
    PHP Code:
    <img src="test.php" /> 

  • #3
    New Coder
    Join Date
    Jul 2006
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fumigator
    How are you executing test.php? You don't execute it like a normal PHP file; you insert it in an img tag like this:
    PHP Code:
    <img src="test.php" /> 
    I tried this at http://www.spurtstudios.com/test2.html but Ijust got a little box with an x in it. Any other suggestions?

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    I really don't know... your code worked for me (I just tried it).

    Maybe try a valid HTML page to test it in.

  • #5
    New Coder
    Join Date
    Jul 2006
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I tried another code that works for me but it only resizes by a percentage.
    You can view it here http://spurtstudios.com/test3.php
    I want to make it have a max height of 100px and stay proportionate though.
    Any way to
    Here it is

    Code:
    <?php
    // The file
    $filename = 'test.jpg';
    $percent = 0.1;
    
    // 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, null, 100);
    ?>

  • #6
    Regular Coder
    Join Date
    Apr 2004
    Posts
    298
    Thanks
    0
    Thanked 23 Times in 23 Posts
    Might look here...

    http://www.nstoia.com/toh/technical/...size/index.php

    it allows you to set max height and/or width, while keeping the result proportional

    Lite...

  • #7
    New Coder
    Join Date
    Jul 2006
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I fixed it myself somehow.
    you can see it hear. http://spurtstudios.com/test5.php
    I'm not sure how I did it but hears the code


    Code:
    <?php
    // The file
    $filename = 'test.jpg';
    
    // Set a maximum height and width
    $width = 200;
    $height = 200;
    // Content type
    header('Content-type: image/jpeg');
    
    // Get new dimensions
    list($widthOrig, $heightOrig) = getimagesize($filename);
    
    if ($widthOrig < $heightOrig) {
       $width = ($height / $heightOrig) * $widthOrig;
    } else {
       $height = ($width / $widthOrig) * $heightOrig;
    }
    
    
    // Resample
    $image_p = imagecreatetruecolor($width, $height);
    $image = imagecreatefromjpeg($filename);
    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $widthOrig, $heightOrig);
    
    // Output
    imagejpeg($image_p, null, 100);
    ?>


  •  

    Posting Permissions

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