So, I have a question about batch processing a folder of images. My situation is that I have a folder with about 1,000 jpgs in it. I need to composite a small png graphic in each frame. The catch is that the png's x,y,width,height, and rotation values are going to be different on every frame.
Currently what I have works fine, but I don't feel like it is the most efficient. Here is what the php code looks like:
Code: Select all
$num = count($positions);
$headFile = 'temp/head.png';
$res='';
for($i = 1; $i<$num; $i++){
$pos = $positions[$i-1];
$frame = new Imagick('temp/frame'.$i.'.png');
if( $pos['valid']){
$w = $pos['width'];
$h = $pos['height'];
$x = ceil( $pos['x'] );
$y = ceil( $pos['y'] - 10 );
$rot = ceil( $pos['rotation'] );
$head = new Imagick($headFile);
$head->resizeImage($w ,$h,Imagick::FILTER_LANCZOS,1);
$head->rotateImage('transparent',$rot);
$frame->compositeImage($head, $head->getImageCompose(), $x, $y);
}
$frame->writeImage('output/frame'.$i.'.jpg');
}
-loop through an array of objects which contains info on how to position the png on each frame
- open the background image ($frame)
- read the head image
- compose the head onto the frame
- save the composed image as a new file
As you can see, I am re-creating the $head file every time through the loop, because it will be modified every time it runs. Is there a more efficient way to do this? Or a better way to do all of it?