Imagick and crop
Posted: Thu May 20, 2010 2:17 am
Hi,
Goal: A function that crops one image multiple times from different y locations (from up to down, only y cordinates) and then saves outputs in a folder
Problem: Im pretty sure my logic in this is messed up, it only ouputs 1 image.
My end goal on this would be slicing the image completely but for now i'd just want to get the function running and then go on with that.
Ok here's what's on my mind.
Say that i have an image of 1024 width and 768 height, when i transform this image into an imagick object i would want to crop this image continually from top until to the end of the image(down side) with 256 pixels a piece.
Here's my code so far:
What am i doing wrong? is the foreach even appropriate to use in this? any alternatives?
Im really stuck on this, any help is greatly appreciated.
Thanks,
Goal: A function that crops one image multiple times from different y locations (from up to down, only y cordinates) and then saves outputs in a folder
Problem: Im pretty sure my logic in this is messed up, it only ouputs 1 image.
My end goal on this would be slicing the image completely but for now i'd just want to get the function running and then go on with that.
Ok here's what's on my mind.
Say that i have an image of 1024 width and 768 height, when i transform this image into an imagick object i would want to crop this image continually from top until to the end of the image(down side) with 256 pixels a piece.
Here's my code so far:
Code: Select all
function sliceImage() {
$ycords = array(0,256,512,768);
for ($i=0; $i<=count($ycords); $i++){
$filename = "pictures/fname_" . $i . ".png";
}
foreach ($ycords as $ystart) {
$file = 'test.png';
$pic = new Imagick($file);
$pic->setImageFormat('png');
$pic->cropImage(256, 256, 0, $ystart);
$pic->writeImage($filename);
}
}What am i doing wrong? is the foreach even appropriate to use in this? any alternatives?
Im really stuck on this, any help is greatly appreciated.
Thanks,