diff --git a/README.md b/README.md index e25bbc1..f569f59 100644 --- a/README.md +++ b/README.md @@ -23,16 +23,17 @@ Test site: https://dev.pictshare.net/ (only sometimes on) - [x] URL - [x] LOG_UPLOADER - [x] FFMPEG_BINARY -- [ ] PNG_COMPRESSION -- [ ] JPEG_COMPRESSION +- [x] PNG_COMPRESSION +- [x] JPEG_COMPRESSION +- [x] WEBP_COMPRESSION - [ ] MASTER_DELETE_CODE - [ ] MASTER_DELETE_IP - [ ] UPLOAD_CODE ### Image hosting -- [ ] Resizing +- [X] Resizing - [ ] Filters -- [ ] Gif to mp4 conversion +- [x] Gif to mp4 conversion - [x] Upload of images ### Text file hosting diff --git a/content-controllers/image/image.controller.php b/content-controllers/image/image.controller.php index 7bb52f3..cbec611 100644 --- a/content-controllers/image/image.controller.php +++ b/content-controllers/image/image.controller.php @@ -126,7 +126,44 @@ class ImageController implements ContentController break; case 'mp4': + $mp4path = ROOT.DS.'data'.DS.$hash.DS.$hash.'mp4'; + if(!file_exists($mp4path)) + $this->gifToMP4($path,$mp4path); + $path = $mp4path; + if(in_array('raw',$url)) + (new VideoController())->serveMP4($path,$hash); + else if(in_array('preview',$url)) + { + $preview = $path.'_preview.jpg'; + if(!file_exists($preview)) + { + (new VideoController())->saveFirstFrameOfMP4($path,$preview); + } + + header ("Content-type: image/jpeg"); + readfile($preview); + + } + else if(in_array('download',$url)) + { + if (file_exists($path)) { + header('Content-Description: File Transfer'); + header('Content-Type: application/octet-stream'); + header('Content-Disposition: attachment; filename="'.basename($path).'"'); + header('Expires: 0'); + header('Cache-Control: must-revalidate'); + header('Pragma: public'); + header('Content-Length: ' . filesize($path)); + readfile($path); + exit; + } + } + else + { + $data = array('url'=>implode('/',$url),'hash'=>$hash,'filesize'=>renderSize(filesize($path))); + renderTemplate('video',$data); + } break; } } @@ -168,6 +205,20 @@ class ImageController implements ContentController return imagecreatefromstring(file_get_contents($path)); } + function gifToMP4($gifpath,$target) + { + $bin = escapeshellcmd(FFMPEG_BINARY); + $file = escapeshellarg($gifpath); + + if(!file_exists($target)) //simple caching.. have to think of something better + { + $cmd = "$bin -f gif -y -i $file -vcodec libx264 -an -profile:v baseline -level 3.0 -pix_fmt yuv420p -vf \"scale=trunc(iw/2)*2:trunc(ih/2)*2\" -f mp4 $target"; + system($cmd); + } + + return $target; + } + function saveObjOfImage($im,$path,$type) { switch($type) diff --git a/templates/main.html b/templates/main.html index 894a2b5..9615eb0 100644 --- a/templates/main.html +++ b/templates/main.html @@ -40,6 +40,9 @@

+