diff --git a/app/Http/Controllers/StatusController.php b/app/Http/Controllers/StatusController.php index 0220b6d0..317baf0b 100644 --- a/app/Http/Controllers/StatusController.php +++ b/app/Http/Controllers/StatusController.php @@ -30,8 +30,8 @@ class StatusController extends Controller $user = Auth::user(); $this->validate($request, [ - 'photo' => 'required|image|max:15000', - 'caption' => 'string|max:150' + 'photo' => 'required|mimes:jpeg,png,bmp,gif|max:' . config('pixelfed.max_photo_size'), + 'caption' => 'string|max:' . config('pixelfed.max_caption_length') ]); $monthHash = hash('sha1', date('Y') . date('m')); diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 60c2aec6..8a21a2a7 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -40,7 +40,6 @@ class AppServiceProvider extends ServiceProvider }); Blade::directive('prettySize', function($expression) { - $size = intval($expression); $precision = 0; $short = true; @@ -51,6 +50,11 @@ class AppServiceProvider extends ServiceProvider $res = round($size, $precision).$units[$i]; return ""; }); + + Blade::directive('maxFileSize', function() { + $value = config('pixelfed.max_photo_size'); + return \App\Util\Lexer\PrettyNumber::size($value, true); + }); } /** diff --git a/app/Util/Lexer/PrettyNumber.php b/app/Util/Lexer/PrettyNumber.php index 80227f6f..23d7ab26 100644 --- a/app/Util/Lexer/PrettyNumber.php +++ b/app/Util/Lexer/PrettyNumber.php @@ -17,4 +17,20 @@ class PrettyNumber { return $expression; } + public static function size($expression, $kb = false) + { + if($kb) { + $expression = $expression * 1024; + } + $size = intval($expression); + $precision = 0; + $short = true; + $units = $short ? + ['B','k','M','G','T','P','E','Z','Y'] : + ['B','kB','MB','GB','TB','PB','EB','ZB','YB']; + for($i = 0; ($size / 1024) > 0.9; $i++, $size /= 1024) {} + $res = round($size, $precision).$units[$i]; + return $res; + } + } \ No newline at end of file diff --git a/app/Util/Media/Image.php b/app/Util/Media/Image.php index a7d53d34..db7641fd 100644 --- a/app/Util/Media/Image.php +++ b/app/Util/Media/Image.php @@ -105,42 +105,25 @@ class Image { $orientation = $ratio['orientation']; try { - $img = Intervention::make($file); + $img = Intervention::make($file)->orientate(); $img->resize($aspect['width'], $aspect['height'], function ($constraint) { $constraint->aspectRatio(); }); - $converted = $this->convertPngToJpeg($path, $thumbnail, $img->extension); + $converted = $this->setBaseName($path, $thumbnail, $img->extension); $newPath = storage_path('app/'.$converted['path']); - $is_png = false; - - if($img->extension == 'png' || $converted['png'] == true) { - \Log::info('PNG detected, ' . json_encode([$img, $converted])); - $is_png = true; - $newPath = str_replace('.png', '.jpeg', $newPath); - $img->encode('jpg', 80)->save($newPath); - if(!$thumbnail) { - @unlink($file); - } - \Log::info('PNG SAVED, ' . json_encode([$img, $newPath])); - } else { - \Log::info('PNG not detected, ' . json_encode([$img, $converted])); - $img->save($newPath, 75); - } + + $img->save($newPath, 75); if(!$thumbnail) { $media->orientation = $orientation; } - if($is_png == true) { - if($thumbnail == false) { + if($thumbnail == true) { + $media->thumbnail_path = $converted['path']; + $media->thumbnail_url = url(Storage::url($converted['path'])); + } else { $media->media_path = $converted['path']; $media->mime = $img->mime; - } - } - - if($thumbnail == true) { - $media->thumbnail_path = $converted['path']; - $media->thumbnail_url = url(Storage::url($converted['path'])); } $media->save(); @@ -150,18 +133,14 @@ class Image { } } - public function convertPngToJpeg($basePath, $thumbnail = false, $extension) + public function setBaseName($basePath, $thumbnail = false, $extension) { $png = false; $path = explode('.', $basePath); $name = ($thumbnail == true) ? $path[0] . '_thumb' : $path[0]; $ext = last($path); $basePath = "{$name}.{$ext}"; - if($extension == 'png' || $ext == 'png') { - $ext = 'jpeg'; - $basePath = "{$name}.{$ext}"; - $png = true; - } + return ['path' => $basePath, 'png' => $png]; } diff --git a/config/pixelfed.php b/config/pixelfed.php index 9c33a56c..9a872e74 100644 --- a/config/pixelfed.php +++ b/config/pixelfed.php @@ -76,5 +76,25 @@ return [ 'remote_follow_enabled' => env('REMOTE_FOLLOW', false), 'activitypub_enabled' => env('ACTIVITY_PUB', false), + + /* + |-------------------------------------------------------------------------- + | Photo file size limit + |-------------------------------------------------------------------------- + | + | Update the max photo size, in KB. + | + */ + 'max_photo_size' => env('MAX_PHOTO_SIZE', 15000), + + /* + |-------------------------------------------------------------------------- + | Caption limit + |-------------------------------------------------------------------------- + | + | Change the caption length limit for new local posts. + | + */ + 'max_caption_length' => env('MAX_CAPTION_LENGTH', 150), ]; \ No newline at end of file diff --git a/resources/assets/sass/custom.scss b/resources/assets/sass/custom.scss index a145f48d..bc24a07e 100644 --- a/resources/assets/sass/custom.scss +++ b/resources/assets/sass/custom.scss @@ -56,9 +56,7 @@ body, button, input, textarea { } .card.status-container .status-photo { - display: -webkit-box !important; - display: -ms-flexbox !important; - display: flex !important; + display: block !important; margin: auto !important; } diff --git a/resources/views/status/show.blade.php b/resources/views/status/show.blade.php index 7c882def..7e6ddc5d 100644 --- a/resources/views/status/show.blade.php +++ b/resources/views/status/show.blade.php @@ -2,86 +2,82 @@ @section('content') -
- {!! $status->rendered ?? e($status->caption) !!} -
-+ {{$status->profile->username}} + {!! $status->rendered ?? e($status->caption) !!} +
+- {{$item->profile->username}} - {!!$item->rendered!!} {{$item->created_at->diffForHumans(null, true, true ,true)}} -
++ {{$item->profile->username}} + {!!$item->rendered!!} {{$item->created_at->diffForHumans(null, true, true ,true)}} +
@endforeach -
{{$status->created_at->diffForHumans()}}
+