mirror of
https://github.com/HaschekSolutions/pictshare.git
synced 2025-11-13 19:56:23 +00:00
Added new setting to force JPGs sent as WebP if supported by the client
This commit is contained in:
@@ -123,7 +123,7 @@ class ImageController implements ContentController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(in_array('webp',$url) && $type!='webp')
|
if( (in_array('webp',$url) && $type!='webp') || ( $this->shouldAlwaysBeWebp() && $type=='jpg' ) )
|
||||||
$modifiers['webp'] = true;
|
$modifiers['webp'] = true;
|
||||||
if(in_array('forcesize',$url) && $modifiers['size'])
|
if(in_array('forcesize',$url) && $modifiers['size'])
|
||||||
$modifiers['forcesize'] = true;
|
$modifiers['forcesize'] = true;
|
||||||
@@ -218,11 +218,14 @@ class ImageController implements ContentController
|
|||||||
|
|
||||||
$this->saveObjOfImage($im,$newpath,$type);
|
$this->saveObjOfImage($im,$newpath,$type);
|
||||||
}
|
}
|
||||||
|
else if($modifiers['webp'])
|
||||||
|
{
|
||||||
|
$type = 'webp';
|
||||||
|
}
|
||||||
$path = $newpath;
|
$path = $newpath;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
switch($type)
|
switch($type)
|
||||||
{
|
{
|
||||||
case 'jpeg':
|
case 'jpeg':
|
||||||
@@ -281,22 +284,41 @@ class ImageController implements ContentController
|
|||||||
|
|
||||||
function saveObjOfImage($im,$path,$type)
|
function saveObjOfImage($im,$path,$type)
|
||||||
{
|
{
|
||||||
|
$tmppath = '/tmp/'.getNewHash($type,12);
|
||||||
switch($type)
|
switch($type)
|
||||||
{
|
{
|
||||||
case 'jpeg':
|
case 'jpeg':
|
||||||
case 'jpg':
|
case 'jpg':
|
||||||
imagejpeg($im,$path,(defined('JPEG_COMPRESSION')?JPEG_COMPRESSION:90));
|
imagejpeg($im,$tmppath,(defined('JPEG_COMPRESSION')?JPEG_COMPRESSION:90));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'png':
|
case 'png':
|
||||||
imagepng($im,$path,(defined('PNG_COMPRESSION')?PNG_COMPRESSION:6));
|
imagepng($im,$tmppath,(defined('PNG_COMPRESSION')?PNG_COMPRESSION:6));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'webp':
|
case 'webp':
|
||||||
imagewebp($im,$path,(defined('WEBP_COMPRESSION')?WEBP_COMPRESSION:80));
|
imagewebp($im,$tmppath,(defined('WEBP_COMPRESSION')?WEBP_COMPRESSION:80));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(file_exists($tmppath) && filesize($tmppath)>0)
|
||||||
|
{
|
||||||
|
rename($tmppath,$path);
|
||||||
return $im;
|
return $im;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function shouldAlwaysBeWebp()
|
||||||
|
{
|
||||||
|
if(defined('ALWAYS_WEBP') && ALWAYS_WEBP && strpos( $_SERVER['HTTP_ACCEPT'], 'image/webp' ) !== false )
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -18,6 +18,8 @@ _maxUploadSize() {
|
|||||||
|
|
||||||
_filePermissions() {
|
_filePermissions() {
|
||||||
chown -R nginx:nginx /var/www
|
chown -R nginx:nginx /var/www
|
||||||
|
touch data/sha1.csv
|
||||||
|
chown nginx:nginx data/sha1.csv
|
||||||
}
|
}
|
||||||
|
|
||||||
_buildConfig() {
|
_buildConfig() {
|
||||||
@@ -65,16 +67,16 @@ if [[ ${MAX_UPLOAD_SIZE:=100} =~ ^[0-9]+$ ]]; then
|
|||||||
_maxUploadSize
|
_maxUploadSize
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# run _filePermissions function unless SKIP_FILEPERMISSIONS is set to true
|
||||||
|
if [[ ${SKIP_FILEPERMISSIONS:=false} != true ]]; then
|
||||||
|
_filePermissions
|
||||||
|
fi
|
||||||
|
|
||||||
echo ' [+] Starting php'
|
echo ' [+] Starting php'
|
||||||
php-fpm7
|
php-fpm7
|
||||||
|
|
||||||
chown -R nginx:nginx /var/www/
|
|
||||||
|
|
||||||
echo ' [+] Creating config'
|
echo ' [+] Creating config'
|
||||||
|
|
||||||
touch data/sha1.csv
|
|
||||||
chown nginx:nginx data/sha1.csv
|
|
||||||
|
|
||||||
_buildConfig > inc/config.inc.php
|
_buildConfig > inc/config.inc.php
|
||||||
|
|
||||||
echo ' [+] Starting nginx'
|
echo ' [+] Starting nginx'
|
||||||
|
|||||||
@@ -18,10 +18,12 @@ In this file you can set the following options. For a simple working example con
|
|||||||
| MASTER_DELETE_IP | IP addr | If set, allows deletion of image no matter what delete code you provided if request is coming from this single IP |
|
| MASTER_DELETE_IP | IP addr | If set, allows deletion of image no matter what delete code you provided if request is coming from this single IP |
|
||||||
| UPLOAD_FORM_LOCATION | string | If set, will only show the upload form if this url is requested. eg if you set it to /secret/upload then you only see the form if you go to http://your.pictshare.server/secret/upload but bare in mind that the uploads [via API](/rtfm/API.md) will still work for anyone|
|
| UPLOAD_FORM_LOCATION | string | If set, will only show the upload form if this url is requested. eg if you set it to /secret/upload then you only see the form if you go to http://your.pictshare.server/secret/upload but bare in mind that the uploads [via API](/rtfm/API.md) will still work for anyone|
|
||||||
| ALLOWED_SUBNET | IPv4 or IPv6 CIDR | If set, will limit uploads to IPs that match this CIDR |
|
| ALLOWED_SUBNET | IPv4 or IPv6 CIDR | If set, will limit uploads to IPs that match this CIDR |
|
||||||
|
| ALWAYS_WEBP | bool | If set to `true`, JPGs will always be served as WebP, if the client supports it (if `image/webp` is in header `HTTP_ACCEPT`) |
|
||||||
| UPLOAD_QUOTA (NOT IMPLEMENTED) | int | Size in MB. If set, will only allow uploads if combined size of uploads on Server is smaller than this value. Does not account for ALT_FOLDER data and resized versions of original uploads won't be added to calculation |
|
| UPLOAD_QUOTA (NOT IMPLEMENTED) | int | Size in MB. If set, will only allow uploads if combined size of uploads on Server is smaller than this value. Does not account for ALT_FOLDER data and resized versions of original uploads won't be added to calculation |
|
||||||
| UPLOAD_CODE (NOT IMPLEMENTED | string | If set, all uploads require this code via GET or POST variable "uploadcode" or upload will fail |
|
| UPLOAD_CODE (NOT IMPLEMENTED | string | If set, all uploads require this code via GET or POST variable "uploadcode" or upload will fail |
|
||||||
| MAX_RESIZED_IMAGES (NOT IMPLEMENTED | string | If set, limits count of resized images/videos per file on server |
|
| MAX_RESIZED_IMAGES (NOT IMPLEMENTED | string | If set, limits count of resized images/videos per file on server |
|
||||||
|
|
||||||
|
|
||||||
# Content controllers
|
# Content controllers
|
||||||
PictShare is not limited to handling just images. Various content types including txt,mp4 and even url shortenings are supported.
|
PictShare is not limited to handling just images. Various content types including txt,mp4 and even url shortenings are supported.
|
||||||
By default all of these are enabled but if you only need one or more, you can whitelist them and all others won't be accessible.
|
By default all of these are enabled but if you only need one or more, you can whitelist them and all others won't be accessible.
|
||||||
|
|||||||
@@ -33,6 +33,14 @@ chown 1000 -R /data/pictshareuploads
|
|||||||
docker run -d -e "MAX_UPLOAD_SIZE=1024" -v /data/pictshareuploads:/var/www/data -p 80:80 --name=pictshare ghcr.io/hascheksolutions/pictshare
|
docker run -d -e "MAX_UPLOAD_SIZE=1024" -v /data/pictshareuploads:/var/www/data -p 80:80 --name=pictshare ghcr.io/hascheksolutions/pictshare
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Development
|
||||||
|
Using these commands it will mount the current directory in the docker container so you can develop locally without building after each change.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker build -t pictshare -f docker/Dockerfile .
|
||||||
|
docker run -it --rm --name pictshare-dev -p 8080:80 -v $(pwd):/var/www -v $(pwd)/data:/var/www/data -e "URL=http://localhost:8080/" -e "SKIP_FILEPERMISSIONS=true" pictshare
|
||||||
|
```
|
||||||
|
|
||||||
## ENV Variables
|
## ENV Variables
|
||||||
There are some ENV variables that only apply to the Docker image
|
There are some ENV variables that only apply to the Docker image
|
||||||
- MAX_UPLOAD_SIZE (int | size in MB that will be used for nginx. default 50)
|
- MAX_UPLOAD_SIZE (int | size in MB that will be used for nginx. default 50)
|
||||||
@@ -53,6 +61,8 @@ Every other variable can be referenced against the [default PictShare configurat
|
|||||||
- LOG_UPLOADER (true/false | log IPs of uploaders)
|
- LOG_UPLOADER (true/false | log IPs of uploaders)
|
||||||
- MAX_RESIZED_IMAGES (int | how many versions of a single image may exist? -1 for infinite)
|
- MAX_RESIZED_IMAGES (int | how many versions of a single image may exist? -1 for infinite)
|
||||||
- SHOW_ERRORS (true/false | show upload/size/server errors?)
|
- SHOW_ERRORS (true/false | show upload/size/server errors?)
|
||||||
|
- SKIP_FILEPERMISSIONS (true/false | enables/disables fixing file permissions on start. default is false)
|
||||||
|
- ALWAYS_WEBP (true/false | Always tries to server JPGs as WEBp if the client supports it. Default is false)
|
||||||
- ALT_FOLDER (path to a folder where all hashes will be copied to and looked for offsite backup via nfs for example)
|
- ALT_FOLDER (path to a folder where all hashes will be copied to and looked for offsite backup via nfs for example)
|
||||||
- S3_BUCKET (string | Name of your S3 bucket)
|
- S3_BUCKET (string | Name of your S3 bucket)
|
||||||
- S3_ACCESS_KEY (string | Access Key for your Bucket)
|
- S3_ACCESS_KEY (string | Access Key for your Bucket)
|
||||||
|
|||||||
Reference in New Issue
Block a user