Styles2304 Posted June 24, 2008 Share Posted June 24, 2008 I'm trying to crop the image: http://l.yimg.com/us.yimg.com/i/us/nws/weather/gr/33n.png down to 177 by 120. I would just do this in photoshop but the image changes (it's not always 33n.png) but always has the same dimensions and is always a png with transparency. I've tried a few of the functions but either couldn't get them to work or they just didn't function as promised. I've also searched these forums and the php manual and this just isn't something I can figure out on my own. If it's a simple script, I would VERY much appreciate it if someone could write it out for me with just a few notes so that I can learn. Thank You, Styles Quote Link to comment Share on other sites More sharing options...
Styles2304 Posted June 24, 2008 Author Share Posted June 24, 2008 /bump Quote Link to comment Share on other sites More sharing options...
.josh Posted June 24, 2008 Share Posted June 24, 2008 by crop do you mean snip the picture down to 177x120 or do you mean scale it down to 177x120? crop means to ch op it down. scale means to make it smaller. Quote Link to comment Share on other sites More sharing options...
Styles2304 Posted June 24, 2008 Author Share Posted June 24, 2008 I definitely mean crop as in to chop it down. I need to remove a substantial part of the lower right of the picture. Take a look at the link and you'll see what I mean . . . it's just transparent nothing . . . I just want the actual weather image. Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted June 24, 2008 Share Posted June 24, 2008 I just came across some code on php.net that works perfectly as I need it to. Here it is.. <?php // Max height and width $max_width = 100; $max_height = 100; // Path to your jpeg $upfile '/path/to/file.jpg'; Header("Content-type: image/jpeg"); $size = GetImageSize($upfile); // Read the size $width = $size[0]; $height = $size[1]; // Proportionally resize the image to the // max sizes specified above $x_ratio = $max_width / $width; $y_ratio = $max_height / $height; if( ($width <= $max_width) && ($height <= $max_height) ) { $tn_width = $width; $tn_height = $height; } elseif (($x_ratio * $height) < $max_height) { $tn_height = ceil($x_ratio * $height); $tn_width = $max_width; } else { $tn_width = ceil($y_ratio * $width); $tn_height = $max_height; } // Increase memory limit to support larger files ini_set('memory_limit', '32M'); // Create the new image! $src = ImageCreateFromJpeg($upfile); $dst = ImageCreateTrueColor($tn_width, $tn_height); ImageCopyResized($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height); ImageJpeg($dst); // Destroy the images ImageDestroy($src); ImageDestroy($dst); ?> mail at soylentgreens dot com 30-Mar-2005 06:37 How about this for cropping images... <?php $imgfile = "img.jpg"; $cropStartX = 300; $cropStartY = 250; $cropW = 200; $cropH = 200; // Create two images $origimg = imagecreatefromjpeg($imgfile); $cropimg = imagecreatetruecolor($cropW,$cropH); // Get the original size list($width, $height) = getimagesize($imgfile); // Crop imagecopyresized($cropimg, $origimg, 0, 0, $cropStartX, $cropStartY, $width, $height, $width, $height); // TODO: write code to save new image // or, just display it like this: header("Content-type: image/jpeg"); imagejpeg($cropimg); // destroy the images imagedestroy($cropimg); imagedestroy($origimg); ?> You'd just need to modify some of the values to do what you need to do. It works perfectly for me Quote Link to comment Share on other sites More sharing options...
Jabop Posted June 24, 2008 Share Posted June 24, 2008 http://www.php.net/gd You are going to have to do some research on GD's functions. Quote Link to comment Share on other sites More sharing options...
discomatt Posted June 24, 2008 Share Posted June 24, 2008 You're far better off finding ( stealing ) all of the weather images and doing it once, manually. Doing this on the fly makes no sense. Quote Link to comment Share on other sites More sharing options...
Styles2304 Posted June 24, 2008 Author Share Posted June 24, 2008 discomatt . . . I'm ashamed of myself lol. I suppose that's the most effective way since it's done once and for all. Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted June 24, 2008 Share Posted June 24, 2008 wtf? the script I gave will do what you need perfectly. You don't have to manually do them all Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.