add a webp threadhold to convert files
This commit is contained in:
parent
c2c6a62ab4
commit
8b116a143f
38
README.md
38
README.md
@ -1,32 +1,34 @@
|
||||
# ShareX Upload Script
|
||||
|
||||
This is a PHP script that lets you easily upload screenshots taken with the ShareX app to your website. ShareX is a popular screenshot tool for Windows that allows you to take screenshots, annotate them, and share them online.
|
||||
This PHP script allows you to effortlessly upload your ShareX app screenshots to your website. ShareX is a widely-used Windows screenshot tool that enables users to take screenshots, annotate them, and share them online.
|
||||
|
||||
## Features
|
||||
|
||||
- Uploads screenshots to your website using ShareX.
|
||||
- Can automatically convert screenshots to WebP format.
|
||||
- Effortlessly upload screenshots to your website using ShareX.
|
||||
- Automatically convert screenshots to WebP format.
|
||||
|
||||
## Installation
|
||||
|
||||
1. Find somewhere to host the script (Preferably more than 5GB of storage).
|
||||
2. Check that your web server has the GD library installed. (See below for instructions on how to install it on Ubuntu.)
|
||||
3. Upload the files to your server.
|
||||
4. Edit the `upload.php` file to configure the script.
|
||||
5. Add the custom uploader to ShareX.
|
||||
6. Configure the custom uploader in ShareX.
|
||||
7. Test it!
|
||||
To install this script:
|
||||
|
||||
## Help
|
||||
- Find a suitable location to host the script (with at least 5GB of storage).
|
||||
- Verify that your web server has the GD library installed. (See instructions below for Ubuntu installation.)
|
||||
- Upload the files to your server.
|
||||
- Edit the `upload.php` file to configure the script.
|
||||
- Add the custom uploader to ShareX.
|
||||
- Configure the custom uploader in ShareX.
|
||||
- Test the script!
|
||||
|
||||
If you need help, you can contact me on Discord at `Fascinated#7668`.
|
||||
## Need Help?
|
||||
|
||||
## How to install GD Library on Ubuntu
|
||||
If you require assistance, feel free to contact me via Discord at Fascinated#7668.
|
||||
|
||||
1. `sudo apt-get install php-gd`
|
||||
2. Add `extension=gd` to your php.ini file.
|
||||
3. Restart your web server and php.
|
||||
## How to Install GD Library on Ubuntu
|
||||
|
||||
## Other
|
||||
- `sudo apt-get install php-gd`
|
||||
- Add extension=gd to your php.ini file.
|
||||
- Restart your web server and php.
|
||||
|
||||
This project is worked on at my Gitea instance: <https://git.fascinated.cc/Fascinated/sharex-php-uploader>
|
||||
## Other Information
|
||||
|
||||
This project is maintained on my Gitea instance: <https://git.fascinated.cc/Fascinated/sharex-php-uploader>
|
||||
|
@ -10,6 +10,7 @@ $tokens = array("set me"); // Your secret keys
|
||||
$uploadDir = "./"; // The upload directory
|
||||
$useRandomFileNames = false; // Use random file names instead of the original file name
|
||||
$fileNameLength = 8; // The length of the random file name
|
||||
$webpThreadhold = 1048576; // The minimum file size for converting to webp (in bytes)
|
||||
|
||||
/**
|
||||
* Check if the token is valid
|
||||
@ -59,7 +60,7 @@ try {
|
||||
die();
|
||||
}
|
||||
|
||||
$target_file = $_FILES["sharex"]["name"]; // File name
|
||||
$target_file = preg_replace("/[^A-Za-z0-9_.]/", '', $_FILES["sharex"]["name"]); // Remove unwanted characters
|
||||
$fileType = pathinfo($target_file, PATHINFO_EXTENSION); // File extension (e.g. png, jpg, etc.)
|
||||
|
||||
// Check if the file already exists
|
||||
@ -76,7 +77,7 @@ try {
|
||||
}
|
||||
|
||||
// Convert the image to webp if applicable
|
||||
if (in_array($fileType, array("png", "jpeg", "jpg"))) {
|
||||
if (in_array($fileType, array("png", "jpeg", "jpg")) && $_FILES["sharex"]["size"] > $webpThreadhold) {
|
||||
$image = imagecreatefromstring(file_get_contents($_FILES["sharex"]["tmp_name"]));
|
||||
$webp_file = pathinfo($finalName, PATHINFO_FILENAME) . ".webp";
|
||||
imagewebp($image, $webp_file, 90); // Convert the image and save it
|
||||
|
Loading…
Reference in New Issue
Block a user