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 3 of 3
  1. #1
    Regular Coder Element's Avatar
    Join Date
    Jul 2004
    Location
    Lynnwood, Washington, US
    Posts
    855
    Thanks
    2
    Thanked 2 Times in 2 Posts

    GD Thumbnail Crop not original images size...

    I'm working on little app to automatically make award images for users. But first, I need to get the basic template down.

    This is alter of "Apply Round Corner PHP-GD" and adds a cropping feature (as it needs to be a thumbnail of the original)

    But I want the crop to be the same resolution as the image. Unfortunately when I use the $source_width, and $source_height, the image is extremely blown up. So I divided that by half, and got what appears to be the resolution, but with cose inspection, it's still a bit big, causing blurring.

    The second, MAIN problem I just found, is if the image height is only lets say 142... The cropped thumb has a blank black space at the bottom where it isn't spanning to, and I can't for the life of me make the image move down, just make the blank space bigger.

    Please, help.

    PHP Code:
    <?php 

      
    //----------------------------------------------------------------
      // Apply Round Corner PHP-GD
      // Revision 2 [2009-07-01]
      // Corrected inconsistent corner problem caused by PHP bug 42685
      //----------------------------------------------------------------

      //
      // source: path or url of a gif/jpeg/png image -- php fopen url wrapper must be enabled if using url
      // radius: corner radius in pixels -- default value is 10
      // colour: corner colour in rgb hex format -- default value is FFFFFF
      //

      
    $source $_GET['src'];
      
    $radius = isset( $_GET"radius" ] ) ? $_GET"radius" ] : 10;
      
    $colour = isset( $_GET"colour" ] ) ? $_GET"colour" ] : "FFFFFF";
      
    $cropWidth 191;
      
    $cropHeight 81;

      
    //
      // 1) open source image and calculate properties
      //

      
    list( $source_width$source_height$source_type ) = getimagesize$source );

      switch ( 
    $source_type )
      {
        case 
    IMAGETYPE_GIF:
          
    $source_image imagecreatefromgif$source );
          break;
        case 
    IMAGETYPE_JPEG:
          
    $source_image imagecreatefromjpeg$source );
          break;
        case 
    IMAGETYPE_PNG:
          
    $source_image imagecreatefrompng$source );
          break;
      }


      
    //getting the top left coordinate
      
    $c1 = array( "x" => round( ( $source_width $cropWidth ) / 20 ), "y" => round( ( $source_height $cropHeight ) / ) );
      
        
    //echo "<p>" . $c1['x'] . "x " . $c1['x'] . "y</p>" .
             //"<p>" . $source_width . "x " . $source_height . "y</p>";
             
      
      
    $thumb imagecreatetruecolor$cropWidth$cropHeight );
      
      
    imagecopyresampled$thumb$source_image00$c1['x'], $c1['y'], $source_width 2$source_height 2$cropWidth$cropHeight );
      
      
    $source_width $cropWidth;
      
    $source_height $cropHeight;
        
      
    //
      // 2) create mask for top-left corner in memory
      //

      
    $corner_image imagecreatetruecolor$radius$radius );
      
    $clear_colour imagecolorallocate$corner_image00);
      
    $solid_colour imagecolorallocate$corner_imagehexdecsubstr$colour0) ), hexdecsubstr$colour2) ),hexdecsubstr$colour4) ) );
      
    imagecolortransparent$corner_image$clear_colour );
      
    imagefill$corner_image00$solid_colour );
      
    imagefilledellipse$corner_image$radius$radius, ( $radius ), ( $radius ), $clear_colour );

      
    //
      // 3) render the top-left, bottom-left, bottom-right, top-right corners by rotating and copying the mask
      //

      
    imagecopymerge$thumb$corner_image0000$radius$radius100 );
      
    $corner_image imagerotate$corner_image90);
      
      
    imagecopymerge$thumb$corner_image0, ( $source_height $radius ), 00$radius$radius100 );
      
    $corner_image imagerotate$corner_image90);

      
    imagecopymerge$thumb$corner_image, ( $source_width $radius ), ( $source_height $radius ), 00$radius$radius100 );
      
    $corner_image imagerotate$corner_image90);
      
      
    imagecopymerge$thumb$corner_image, ( $source_width $radius ), 000$radius$radius100 );

      
    //
      // 4) output the image -- revise this step according to your needs
      //

      
    header"Content-type: image/png" );
      
    imagepng$thumb );
      
    ?>
    The code in question is this block:

    PHP Code:
     //getting the top left coordinate
      
    $c1 = array( "x" => round( ( $source_width $cropWidth ) / 20 ), "y" => round( ( $source_height $cropHeight ) / ) );
      
        
    //echo "<p>" . $c1['x'] . "x " . $c1['x'] . "y</p>" .
             //"<p>" . $source_width . "x " . $source_height . "y</p>";
             
      
      
    $thumb imagecreatetruecolor$cropWidth$cropHeight );
      
      
    imagecopyresampled$thumb$source_image00$c1['x'], $c1['y'], $source_width 2$source_height 2$cropWidth$cropHeight );
      
      
    $source_width $cropWidth;
      
    $source_height $cropHeight

  • #2
    Regular Coder Element's Avatar
    Join Date
    Jul 2004
    Location
    Lynnwood, Washington, US
    Posts
    855
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Solved it. Thanks anyways.

  • #3
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi

    I need a VB4 thumbnail resize or crop option when people upload images.

    I need a fixed width/height size of the thumbnails.

    Are you able to do that? Id pay you.

    Thanks,
    Bob


  •  

    Posting Permissions

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