|
|
|
@ -0,0 +1,153 @@
|
|
|
|
|
<?php
|
|
|
|
|
/* This is free and unencumbered software released into the public domain.
|
|
|
|
|
*
|
|
|
|
|
* Anyone is free to copy, modify, publish, use, compile, sell, or
|
|
|
|
|
* distribute this software, either in source code form or as a compiled
|
|
|
|
|
* binary, for any purpose, commercial or non-commercial, and by any
|
|
|
|
|
* means.
|
|
|
|
|
*
|
|
|
|
|
* In jurisdictions that recognize copyright laws, the author or authors
|
|
|
|
|
* of this software dedicate any and all copyright interest in the
|
|
|
|
|
* software to the public domain. We make this dedication for the benefit
|
|
|
|
|
* of the public at large and to the detriment of our heirs and
|
|
|
|
|
* successors. We intend this dedication to be an overt act of
|
|
|
|
|
* relinquishment in perpetuity of all present and future rights to this
|
|
|
|
|
* software under copyright law.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*
|
|
|
|
|
* For more information, please refer to <http://unlicense.org/>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Return source code
|
|
|
|
|
if(isset($_GET['source'])) {
|
|
|
|
|
header("Content-Type: text/plain");
|
|
|
|
|
die(file_get_contents(basename($_SERVER['PHP_SELF'])));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function convert() {
|
|
|
|
|
$files = $_FILES['files'];
|
|
|
|
|
|
|
|
|
|
if($files['error'][0])
|
|
|
|
|
return "You must upload at least one image and GRIT file";
|
|
|
|
|
|
|
|
|
|
for($i = 0; $i < count($files['name']); $i++) {
|
|
|
|
|
if(!empty($files['tmp_name'][$i]) && $files['error'][$i] == 0) {
|
|
|
|
|
if($files['type'][$i] == 'image/png' || $files['type'][$i] == 'image/bmp') {
|
|
|
|
|
$grit = array_search(preg_replace('/\.(?:png|bmp)/', '.grit', $files['name'][$i]), $files['name']);
|
|
|
|
|
if($grit !== false) {
|
|
|
|
|
if(move_uploaded_file($files['tmp_name'][$i], 'temp/' . $files['name'][$i])
|
|
|
|
|
&& move_uploaded_file($files['tmp_name'][$grit], 'temp/' . $files['name'][$grit])) {
|
|
|
|
|
$output = null;
|
|
|
|
|
$ret = null;
|
|
|
|
|
exec("grit 'temp/{$files['name'][$i]}' -ftr -fh! -o'temp/{$files['name'][$i]}'", $output, $ret);
|
|
|
|
|
if($ret != 0)
|
|
|
|
|
return "grit conversion failed on image {$files['name'][$i]}";
|
|
|
|
|
} else {
|
|
|
|
|
return "Unable to upload image {$files['name'][$i]}, please contact the webmaster";
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return "Image {$files['name'][$i]} is missing a .grit file";
|
|
|
|
|
}
|
|
|
|
|
} else if($files['type'][$i] == 'application/octet-stream' && preg_match('/\.grit$/', $files['name'][$i])) {
|
|
|
|
|
if(array_search(preg_replace('/\.grit/', '.png', $files['name'][$i]), $files['name']) === false
|
|
|
|
|
&& array_search(preg_replace('/\.grit/', '.bmp', $files['name'][$i]), $files['name']) === false) {
|
|
|
|
|
return "GRIT file {$files['name'][$i]} is missing an image";
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return "Files must be PNG/BMP images with matching GRIT files";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function cleanup() {
|
|
|
|
|
foreach($_FILES['files']['tmp_name'] as $file) {
|
|
|
|
|
@unlink($file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach($_FILES['files']['name'] as $file) {
|
|
|
|
|
@unlink('temp/' . $file);
|
|
|
|
|
@unlink('temp/' . preg_replace('/\.(?:png|bmp)/', '.grf', $file));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ceanup old files
|
|
|
|
|
$dir = opendir('temp');
|
|
|
|
|
if ($dir) {
|
|
|
|
|
while (($file = readdir($dir)) !== false) {
|
|
|
|
|
@unlink('temp/' . $file);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
closedir($dir);
|
|
|
|
|
|
|
|
|
|
if($_POST['submit'] == 'Convert') {
|
|
|
|
|
$err = convert();
|
|
|
|
|
|
|
|
|
|
if(empty($err)) {
|
|
|
|
|
$output = null;
|
|
|
|
|
$ret = null;
|
|
|
|
|
$zipName = time() . '.zip';
|
|
|
|
|
exec("cd temp && 7z a $zipName *.grf", $output, $ret);
|
|
|
|
|
|
|
|
|
|
if($ret == 0) {
|
|
|
|
|
header('Content-Type: application/zip');
|
|
|
|
|
header('Content-Transfer-Encoding: Binary');
|
|
|
|
|
header('Content-Disposition: attachment; filename="converted.zip"');
|
|
|
|
|
readfile("temp/$zipName");
|
|
|
|
|
cleanup();
|
|
|
|
|
exit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cleanup();
|
|
|
|
|
}
|
|
|
|
|
?>
|
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html lang="en">
|
|
|
|
|
<head>
|
|
|
|
|
<meta charset="utf-8">
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
|
|
|
|
|
|
|
|
<title>GRIT | ピケ.コム</title>
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
<form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
|
|
|
|
|
<fieldset id="bottom">
|
|
|
|
|
<legend>Online GRIT converter</legend>
|
|
|
|
|
|
|
|
|
|
<table>
|
|
|
|
|
<tr>
|
|
|
|
|
<td><label for="files">Files:</label></td>
|
|
|
|
|
<td><input type="file" id="files" name="files[]" accept=".png,.bmp,.grit" multiple></td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td></td>
|
|
|
|
|
<td><input type="submit" value="Convert" name="submit"></td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
|
|
|
|
|
<?php if(!empty($err)) echo "<br><strong>$err</strong>"; ?>
|
|
|
|
|
</fieldset>
|
|
|
|
|
</form>
|
|
|
|
|
|
|
|
|
|
<p>You must upload one .png or .bmp image and one .grit file for each image you want converted. Uploading multiple pairs of images and GRIT files at a time is supported.</p>
|
|
|
|
|
<p>A ZIP file with your converted GRF files inside will then be downloaded.</p>
|
|
|
|
|
<p>
|
|
|
|
|
If you graphics come out corrupted it's probably because the palettes are somehow wrong.
|
|
|
|
|
Check that there aren't more colors in the image than the <code>-pn</code> in your GRIT file. (ex. <code>-pn32</code> is 32 colors)
|
|
|
|
|
It may work better to upload a non-paletted image depending on the image.
|
|
|
|
|
<p>
|
|
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
[<a href="//xn--rck9c.xn--tckwe">back</a>]
|
|
|
|
|
[<a href="?source">source</a>]
|
|
|
|
|
<p>
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|