-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathanimate-image.php
executable file
·41 lines (33 loc) · 1.07 KB
/
animate-image.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env php
<?php
require dirname(__DIR__) . '/vendor/autoload.php';
use Jcupitt\Vips;
#Vips\Config::setLogger(new Vips\DebugLogger());
if (count($argv) != 4) {
echo("usage: ./animate-image.php input-image output-image 'text string'\n");
exit(1);
}
$image = Vips\Image::newFromFile($argv[1]);
$text = Vips\Image::text($argv[3], ["dpi" => 300, "rgba" => true]);
$animation = null;
$delay = [];
for ($x = 0; $x < $image->width + $text->width; $x += 10) {
// append the frame to the image vertically ... we make a very tall, thin
// strip of frames to save
$frame = $image->composite2($text, "over", [
"x" => $x - $text->width,
"y" => $image->height / 2 - $text->height / 2
]);
if ($animation == null) {
$animation = $frame;
} else {
$animation = $animation->join($frame, "vertical");
}
// frame delay in ms
array_push($delay, 30);
}
// set animation properties
$animation->set("delay", $delay);
$animation->set("loop", 0);
$animation->set("page-height", $image->height);
$animation->writeToFile($argv[2]);