I have seen tons of examples of Cropping images with php & the gd lib however I have never seen any posts on Skimming or Shaving an image. What I mean by this is say you have pictures from a digital camera that places the date on picture. It is always in a constant place on the picture. So how would I do this? All examples I have come across deal with maintaining an aspect ratio which i just want those 75px or so off the bottom. how could this be done the easiest ? I found this example somewhat enlightening! http://stackoverflow.com/questions/3604940/imagecopyresampled-in-php-can-someone-explain-it
A:
To create what you need just read this page: http://us.php.net/imagecopy
You can use something like this and just change the $left and $top to correspond to where the date stamp is on the image.
<?php
// Original image
$filename = 'someimage.jpg';
// Get dimensions of the original image
list($current_width, $current_height) = getimagesize($filename);
// The x and y coordinates on the original image where we
// will begin cropping the image
$left = 50;
$top = 50;
// This will be the final size of the image (e.g. how many pixels
// left and down we will be going)
$crop_width = 200;
$crop_height = 200;
// Resample the image
$canvas = imagecreatetruecolor($crop_width, $crop_height);
$current_image = imagecreatefromjpeg($filename);
imagecopy($canvas, $current_image, 0, 0, $left, $top, $current_width, $current_height);
imagejpeg($canvas, $filename, 100);
?>
A similar example is:
Basic way to implement a "crop" feature : given an image (src), an offset (x, y) and a size (w, h).
crop.php :
<?php
$w=$_GET['w'];
$h=isset($_GET['h'])?$_GET['h']:$w; // h est facultatif, =w par défaut
$x=isset($_GET['x'])?$_GET['x']:0; // x est facultatif, 0 par défaut
$y=isset($_GET['y'])?$_GET['y']:0; // y est facultatif, 0 par défaut
$filename=$_GET['src'];
header('Content-type: image/jpg');
header('Content-Disposition: attachment; filename='.$src);
$image = imagecreatefromjpeg($filename);
$crop = imagecreatetruecolor($w,$h);
imagecopy ( $crop, $image, 0, 0, $x, $y, $w, $h );
imagejpeg($crop);
?>
Call it like this :
<img src="crop.php?x=10&y=20&w=30&h=40&src=photo.jpg">
Todd Moses
2010-09-14 18:11:12
Ok date and time stamps always in the lower right corner so in your example i should do this.$skim = 75; $left = 0; $top = 0; (to start at the top left/top 0 position) then $crop_width = imagesx($file); $crop_height = (imagesy($file) - $skim); Like i said before i am not trying to thumbnail it with a 200x200 w/h ratio nor trying to maintain any aspects as Skimming 75px off the entire image is really not even seen
dominicdinada
2010-09-14 20:14:30
Imagecopy didnt work all it does is fills the same image with blackspace over the area that is supposed to be cropped. but it made me look alot closer at the link that i provided.
dominicdinada
2010-09-14 21:34:16