-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy paththumbs_fix.php
85 lines (82 loc) · 2.11 KB
/
thumbs_fix.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
set_time_limit(0);
require "inv.header.php";
$user = new user();
if(!$user->gotpermission('is_admin'))
{
header('Location: index.php');
exit;
}
$image = new image();
$new_count = 0;
$fail_count = 0;
function is_valid_extension($img)
{
$ext = strrchr($img,".");
$ext = substr($ext, 1);
switch($ext)
{
case "jpg":
case "gif":
case "png":
case "bmp":
case "webp":
case "webm":
case "mp4":
return true;
break;
default:
return false;
}
}
$dirs = array();
$dir = "./$image_folder/";
$dir_contents = scandir($dir);
foreach ($dir_contents as $item)
{
if (is_dir($dir.$item) && $item != '.' && $item != '..')
{
$dirs[] = $item;
}
}
foreach($dirs as $current)
{
$dir_contents = scandir("./$image_folder/".$current."/");
foreach ($dir_contents as $item)
{
$thumb = "./$thumbnail_folder/$current/thumbnail_$item";
$ext = strrchr($item,".");
$ext = substr($ext, 1);
if($ext == "webm" || $ext == "mp4")
{
$thumb = str_replace(".$ext", ".png", $thumb);
}
if ($item != '.' && $item != '..' && !is_dir($dir.$item) && is_valid_extension($item) && !file_exists($thumb))
{
print "<br/><a href='$image_folder/$current/$item'>$image_folder/$current/$item</a><br/>thumb: $thumb<br/>";
$image = new image();
if(!$image->load("./$image_folder/$current/$item"))
{
$fail_count++;
print "Error loading metadata for $current/$item: ".$image->geterror()."<br/><br/>";
continue;
}
if(!is_dir("./$thumbnail_folder/".$current."/"))
$image->makethumbnailfolder($current);
if( $image->thumbnail($current."/".$item) )
{
$new_count++;
print "<span style='color:green'>$thumb</span> <a href='$thumb'>link</a><br><br/>";
}
else
{
$fail_count++;
print "<span style='color:red'>$thumb failed</span>. <a href='./$image_folder/$current/$item'>Source image</a> might be corrupted<br/><br/>";
}
}
}
}
print "<hr/>
Thumbnails created: $new_count<br/>
Thumbnails failed: $fail_count<br/>";
?>