Skip to content

Commit 24831a1

Browse files
committedNov 9, 2023
add animate-image.php example
1 parent 14df899 commit 24831a1

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
 

‎CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ All notable changes to `:vips` will be documented in this file.
44

55
## master
66

7+
- added `animate-image.php` example [jcupitt]
8+
79
## 2.3.0 - 2023-09-26
810

911
- add getFields() to fetch an array of field names [jcupitt]

‎examples/animate-image.php

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

0 commit comments

Comments
 (0)
Failed to load comments.