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 14 of 14
  1. #1
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question imagecreatetruecolor help !

    i've got this code (in the midst of a bunch of other code):

    PHP Code:
    $file $_POST['file'];
    $trgt_w $_POST['w'];
    $trgt_h $_POST['h'];

    list(
    $w$h) = getimagesize($file);
    echo 
    "w " $w ", h " $h;

    $src imagecreatefromjpeg($file);
    echo 
    " imagecreatefromjpeg";

    $thm imagecreatetruecolor($trgt_w$trgt_h);
    echo 
    " imagecreatetruecolor"
    I noticed that my code wasn't always executing all the way through. So, I put in those echo lines, and noticed that for SOME images, the "imagecreatetruecolor" echo line never gets executed.

    It seems that for larger, say desktop background sized, images, the code quits before getting to that echo line... as it never returns that echo. For smaller images, the code works through that line and perfectly through the rest of the code.

    I don't know a ton of PHP, so I am at an impass here. Anything strike anyone as to why this code wouldn't work for larger images? It needs to work for larger images. Am I missing something else?

  • #2
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    PHP Code:
    $file $_POST['file'];
    $trgt_w $_POST['w'];
    $trgt_h $_POST['h'];

    list(
    $w$h) = getimagesize($file);
    echo 
    "w : $w , h : $h; // no concatination needed.

    $src = imagecreatefromjpeg($file);
    echo " 
    imagecreatefromjpeg$file."; //echo more values

    $thm = imagecreatetruecolor($trgt_w, $trgt_h);
    echo " 
    imagecreatetruecolor$trgt_w $trgt_h.";  // echo more values 

  • #3
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yeah, those echo lines are just for debugging – all the variables come through when i modify the code as you describe.

    except, still for larger images, the echo " imagecreatetruecolor: $trgt_w : $trgt_h." doesn't come out of the php, as if the code is quitting completely right before that line.

  • #4
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    sorry i missed a " try
    echo "w : $w , h : $h"; // no concatination needed.
    do you have an onlin example of the code at work, also turn on full error reporting.

  • #5
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i'm actually calling the php through flash, which doesn't let you see any of the errors (hence the echoes for debugging).

    let me see if i can get something non-flash hooked up real quick...

  • #6
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    also, how do i turn on full error reporting with php ?

  • #7
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    look up error_reporting() on php.net/error-reporting

  • #8
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #9
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Aaeeight ... here we go... i've got a demo basically showing what happens up at http://sccottt.com/coding_forums/

    the php is such:

    PHP Code:
    <?php

        error_reporting
    (E_ALL);

        
    $file            $_POST['file'];
        
    $new_file        $_POST['newFile'];
        
    $trgt_w            $_POST['w'];
        
    $trgt_h            $_POST['h'];
        
    $delete_orig    $_POST['deleteOrig'];

        if (
    strlen($file) > &&
            
    strlen($new_file) > &&
            
    strlen($trgt_w) > &&
            
    strlen($trgt_h) > &&
            
    strlen($delete_orig) > 0) {

            list(
    $w$h)    = getimagesize($file);
            echo 
    "w: $w, h: $h";

            
    $src            imagecreatefromjpeg($file);
            echo 
    " imagecreatefromjpeg( $file )";

            
    $thm            imagecreatetruecolor($trgt_w$trgt_h);
            echo 
    " imagecreatetruecolor ( $trgt_w , $trgt_h )";

            
    $wm                $w $trgt_w;
            
    $hm                $h $trgt_h;
            
    $half_trgt_w    $trgt_w 2;
            
    $half_trgt_h    $trgt_h 2;

            if (
    $wm $hm) {
                
    $adj_w        $w $hm;
                
    $half_w        $adj_w 2;
                
    $int_w        $half_w $half_trgt_w;
                
    imagecopyresampled($thm$src, -$int_w000$adj_w$trgt_h$w$h);

            } elseif ((
    $wm $hm) || ($wm == $hm)) {
                
    $adj_h        $h $wm;
                
    $half_h        $adj_h 2;
                
    $int_h        $half_h $half_trgt_h;
                
    imagecopyresampled($thm$src0, -$int_h00$trgt_w$adj_h$w$h);

            } else {
                
    imagecopyresampled($thm$src0000$trgt_w$trgt_h$w$h);

            }
            
    imagejpeg($thm$new_file100);

            if (
    $delete_orig == "true") {
                
    unlink($file);
            }
        }

        echo 
    "<br><br>Original:<br><img src=$file><br><br>New (supposed to be resized):<br><img src=$new_file>";

    ?>
    and... well, you can read the HTML


    here you can see, when i try a larger image (http://sccottt.com/coding_forums/bigger.jpg), the code seems to quit in the middle of it.

  • #10
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ahh... no sh*t, it started working !

  • #11
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    lol Congratulations

  • #12
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This must be a problem with my MAMP server running on my computer.

    Seems to work online.


    Damn, I am so embarrassed.

  • #13
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    heh, theres always misconfigurations on local servers as to live servers which mess up the script dont worry about it it happens to all of us...

  • #14
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    well, thanks anyhow


  •  

    Posting Permissions

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