-
Notifications
You must be signed in to change notification settings - Fork 2
/
regenerateImages.php
51 lines (39 loc) · 1.68 KB
/
regenerateImages.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
42
43
44
45
46
47
48
49
50
51
<?php
namespace ProcessWire;
set_time_limit(0);
ini_set('max_execution_time', 0);
// include processwire api
include_once(__DIR__ . "/../../../index.php");
// if not executed over cli
if(!$config->cli) exit();
$ImageBlurhash = $modules->get("ImageBlurhash");
foreach ($fields->find("type=FieldtypeImage") as $field) {
if(isset($field->createBlurhash) && $field->createBlurhash) {
foreach ($pages->find("$field.count>0, check_access=0") as $page) {
foreach ($page->getUnformatted($field->name) as $image) {
$file = null;
if(file_exists($image->filename)) {
if(!exif_imagetype($image->filename)) continue;
$file = $image->filename;
} else {
// optional loading image over HTTP for some special internal cases at Blue Tomato when image does not exist in the filepath
$file = $image->url;
}
echo "Try {$image->name} in {$field->name} \n";
$blurhash = $ImageBlurhash->createBlurhash($file);
if ($blurhash) {
$success = $ImageBlurhash->insertBlurhash($blurhash, $page, $field, $image);
if($success) {
echo "Blurhash saved for {$image->name} in {$field->name} \n";
} else {
echo "Error: Insert Blurhash failed {$image->name} in {$field->name} \n";
}
} else {
echo "Error: Blurhash generation failed {$image->name} in {$field->name} \n";
}
}
}
}
}
echo "All done";
exit();