commit d026bc4047520d6c5a3bc59b27bd59f028fec766 Author: Pk11 Date: Fri May 27 06:35:24 2022 -0500 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..06c7bfa --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +temp/* +!temp/.gitkeep diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..68a49da --- /dev/null +++ b/LICENSE @@ -0,0 +1,24 @@ +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 diff --git a/README.md b/README.md new file mode 100644 index 0000000..9ae7de0 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# GRIT.ピケ.コム + +a little PHP page for doing [GRIT](http://www.coranac.com/projects/grit/) conversions in a browser + +## hosting +1. install: + - PHP (I use 7.3.31) + - GRIT (I use v0.8.18, see [devkitPro pacman][dkp-pacman]) +2. clone this repo, `git clone https://git.xn--rck9c.xn--tckwe/pk11/grit.git` + +[dkp-pacman]: https://devkitpro.org/wiki/Getting_Started diff --git a/index.php b/index.php new file mode 100644 index 0000000..9fe01ac --- /dev/null +++ b/index.php @@ -0,0 +1,153 @@ + + */ + + // 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(); + } +?> + + + + + + + GRIT | ピケ.コム + + +
+
+ Online GRIT converter + + + + + + + + + + +
+ + $err"; ?> +
+
+ +

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.

+

A ZIP file with your converted GRF files inside will then be downloaded.

+

+ 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 -pn in your GRIT file. (ex. -pn32 is 32 colors) + It may work better to upload a non-paletted image depending on the image. +

+ +

+ [back] + [source] +

+ + diff --git a/temp/.gitkeep b/temp/.gitkeep new file mode 100644 index 0000000..e69de29