forked from kalcaddle/KodExplorer
-
Notifications
You must be signed in to change notification settings - Fork 19
/
convert.php
64 lines (44 loc) · 1.38 KB
/
convert.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
<?php
set_time_limit(0);
$folder = trim( $argv[1] );
if( strlen($folder) < 1 ) die('bad args');
$path = $folder;
$path = str_replace('..', '', $path);
$data['base'] = 'comic/'.$path.'/';
$files = './'.$data['base'] . '*.{jpg,png,jpeg}';
//echo $files;
foreach (glob( $files , GLOB_BRACE ) as $filename) {
echo "dealing ... $filename\r\n";
resizeImage( $filename , 2000 , 1080 );
}
echo 'done';
function resizeImage($filename, $max_width, $max_height)
{
$ext = strtolower(end(explode('.',$filename))) ;
list($orig_width, $orig_height) = getimagesize($filename);
$width = $orig_width;
$height = $orig_height;
# taller
if ($height > $max_height) {
$width = ($max_height / $height) * $width;
$height = $max_height;
}
# wider
if ($width > $max_width) {
$height = ($max_width / $width) * $height;
$width = $max_width;
}
$image_p = imagecreatetruecolor($width, $height);
if( $ext == 'png' )
$image = imagecreatefrompng($filename);
else
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0,
$width, $height, $orig_width, $orig_height);
if( $ext == 'png' )
imagepng($image_p,$filename);
else
imagejpeg($image_p,$filename);
imagedestroy($image_p);
imagedestroy($image);
}