forked from One-Piece-Online/OPOnline
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzzImageConverter.php
More file actions
83 lines (78 loc) · 2.95 KB
/
Copy pathzzImageConverter.php
File metadata and controls
83 lines (78 loc) · 2.95 KB
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
<?php
function CheckImage($cardID, $url, $isBack=false)
{
$filename = "./WebpImages/" . $cardID . ".webp";
$filenameNew = "./New Cards/" . $cardID . ".webp";
$concatFilename = "./concat/" . $cardID . ".webp";
$cropFilename = "./crops/" . $cardID . "_cropped.png";
$isNew = false;
if(!file_exists($filename))
{
$imageURL = $url;
echo("Image for " . $cardID . " does not exist.<BR>");
$handler = fopen($filename, "w");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $imageURL);
curl_setopt($ch, CURLOPT_FILE, $handler);
curl_exec($ch);
curl_close($ch);
//if(filesize($filename) < 10000) { unlink($filename); return; }
echo(filesize($filename));
if(file_exists($filename)) echo("Image for " . $cardID . " successfully retrieved.<BR>");
if(file_exists($filename))
{
echo("Normalizing file size for " . $cardID . ".<BR>");
$image = imagecreatefrompng($filename);
//$image = imagecreatefromjpeg($filename);
$image = imagescale($image, 450, 628);
imagewebp($image, $filename);
// Free up memory
imagedestroy($image);
}
$isNew = true;
}
if($isNew && !file_exists($filenameNew)) {
echo("Converting image for " . $cardID . " to new format.<BR>");
$image = imagecreatefromwebp($filename);
//$image = imagecreatefrompng($filename);
imagewebp($image, $filenameNew);
imagedestroy($image);
}
if(!file_exists($concatFilename))
{
echo("Concat image for " . $cardID . " does not exist. Converting: $filename<BR>");
if(file_exists($filename))
{
echo("Attempting to convert image for " . $cardID . " to concat.<BR>");
$image = imagecreatefromwebp($filename);
//$image = imagecreatefrompng($filename);
$imageTop = imagecrop($image, ['x' => 0, 'y' => 0, 'width' => 450, 'height' => 372]);
$imageBottom = imagecrop($image, ['x' => 0, 'y' => 570, 'width' => 450, 'height' => 628]);
$dest = imagecreatetruecolor(450, 450);
imagecopy($dest, $imageTop, 0, 0, 0, 0, 450, 372);
imagecopy($dest, $imageBottom, 0, 373, 0, 0, 450, 78);
imagewebp($dest, $concatFilename);
// Free up memory
imagedestroy($image);
imagedestroy($dest);
imagedestroy($imageTop);
imagedestroy($imageBottom);
if(file_exists($concatFilename)) echo("Image for " . $cardID . " successfully converted to concat.<BR>");
}
}
if(!file_exists($cropFilename))
{
echo("Crop image for " . $cardID . " does not exist.<BR>");
if(file_exists($filename))
{
echo("Attempting to convert image for " . $cardID . " to crops.<BR>");
$image = imagecreatefromwebp($filename);
//$image = imagecreatefrompng($filename);
$image = imagecrop($image, ['x' => 50, 'y' => 100, 'width' => 350, 'height' => 270]);
imagepng($image, $cropFilename);
imagedestroy($image);
if(file_exists($cropFilename)) echo("Image for " . $cardID . " successfully converted to crops.<BR>");
}
}
}
?>