Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'gd library'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Single Editions
    • Modern Javascript: Develop and Design
    • The Yii Book
    • Effortless Flex 4 Development
    • Building a Web Site with Ajax: Visual QuickProject
    • Ruby: Visual QuickStart Guide
    • C++ Programming: Visual QuickStart Guide
    • C Programming: Visual QuickStart Guide
    • Adobe AIR: Visual QuickPro Guide
  • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (5th Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
    • PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (1st Edition)
  • PHP for the Web: Visual QuickStart Guide
    • PHP for the Web: Visual QuickStart Guide (5th Edition)
    • PHP for the Web: Visual QuickStart Guide (4th Edition)
    • PHP for the Web: Visual QuickStart Guide (3rd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (2nd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (1st Edition)
  • Effortless E-commerce with PHP and MySQL
    • Effortless E-Commerce with PHP and MySQL (2nd Edition)
    • Effortless E-Commerce with PHP and MySQL
  • PHP Advanced: Visual QuickPro Guide
    • PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide (3rd Edition)
    • PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
    • PHP Advanced: Visual QuickPro Guide
  • MySQL: Visual QuickStart Guide
    • MySQL: Visual QuickStart Guide (2nd Edition)
    • MySQL: Visual QuickStart Guide (1st Edition)
  • Other
    • Announcements
    • Newsletter, Blog, and Other Topics
    • Forum Issues
    • Social

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Found 1 result

  1. Hi Larry, I have another piece of code that I just can't make work properly. I have Googled and I think that I'm using the correct code but all I get is a jpg image of the correct size and shape but it is blank. $newname is a relative URL to a large jpg image file that I know is there. I need a square thumbnail jpg image so I'm trying to crop the original image correctly to a square and also downsize it. I definitely have the GD library in my PHP. // crop and resize the image file // Get dimensions of the original image list($current_width, $current_height) = getimagesize($newname); echo "<p><font color='yellow'>Current width is $current_width, current height is $current_height.</font></p>"; // now work out the x and y coordinates on the original image where we // will begin cropping the image if ($current_width > $current_height) { // image type = "Landscape" $left = ($current_width - $current_height) / 2; $top = 0; $new_width = $current_width - (2 * $left); $new_height = $current_height; } elseif ($current_height > $current_width) { // image type = "Portrait" $top = ($current_height - $current_width) / 2; $left = 0; $new_width = $current_width; $new_height = $current_height - (2 * $top); } else { // image is square $top = 0; $left = 0; } // This will be the final size of the image (e.g. how many pixels // left and down we will be going) $crop_width = (int) $_POST['size']; $crop_height = (int) $_POST['size']; echo "<p><font color='yellow'>Parameters are left: $left, top: $top, new width: $new_width, new height: $new_height.</font></p>"; // Resample the image $canvas = imagecreatetruecolor($crop_width, $crop_height); $current_image = imagecreatefromjpeg($newname); imagecopy($canvas, $current_image, 0, 0, $left, $top, $new_width, $new_height); // imagecopy($canvas, $current_image, 0, 0, 0, 0, $current_width, $current_height); /* the imagecopy parameters are: 1) Destination image link resource 2) Source image link resource 3) x-coordinate of destination point 4) y-coordinate of destination point 5) x-coordinate of source point 6) y-coordinate of source point 7) Source width 8) Source height */ header('Content-Type: image/jpeg'); imagejpeg($canvas, $newname, 100); Any help will be appreciated. Cheers from Oz.
×
×
  • Create New...