From b437b627802fcba7800e22569b47a20d645a21d2 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 2 Jun 2018 15:29:33 -0600 Subject: [PATCH 1/5] Update Image class, remove PNG -> JPEG conversion and use orientate() method to detect proper orientation in Exif --- app/Util/Media/Image.php | 41 ++++++++++------------------------------ 1 file changed, 10 insertions(+), 31 deletions(-) diff --git a/app/Util/Media/Image.php b/app/Util/Media/Image.php index a7d53d34a..db7641fd3 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]; } From c53e9635370f377bf592f8b199544f1a9e472b01 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 2 Jun 2018 16:53:35 -0600 Subject: [PATCH 2/5] Add supported file types and max caption length to new post form. Closes #121 and #136 --- app/Http/Controllers/StatusController.php | 4 ++-- app/Providers/AppServiceProvider.php | 6 ++++- app/Util/Lexer/PrettyNumber.php | 16 +++++++++++++ config/pixelfed.php | 20 ++++++++++++++++ .../views/timeline/partial/new-form.blade.php | 23 +++++++++++++++++++ resources/views/timeline/personal.blade.php | 19 ++------------- resources/views/timeline/public.blade.php | 19 ++------------- 7 files changed, 70 insertions(+), 37 deletions(-) create mode 100644 resources/views/timeline/partial/new-form.blade.php diff --git a/app/Http/Controllers/StatusController.php b/app/Http/Controllers/StatusController.php index 0220b6d0f..317baf0b0 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 60c2aec65..8a21a2a7d 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 80227f6fe..23d7ab267 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/config/pixelfed.php b/config/pixelfed.php index 9c33a56cf..9a872e74c 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/views/timeline/partial/new-form.blade.php b/resources/views/timeline/partial/new-form.blade.php new file mode 100644 index 000000000..104e4de57 --- /dev/null +++ b/resources/views/timeline/partial/new-form.blade.php @@ -0,0 +1,23 @@ +
+
New Post
+
+
+ @csrf +
+ + + + Max Size: @maxFileSize(). Supported formats: jpeg, png, gif, bmp. + +
+
+ + + + Max length: {{config('pixelfed.max_caption_length')}} characters. + +
+ +
+
+
\ No newline at end of file diff --git a/resources/views/timeline/personal.blade.php b/resources/views/timeline/personal.blade.php index b10490638..ce9415638 100644 --- a/resources/views/timeline/personal.blade.php +++ b/resources/views/timeline/personal.blade.php @@ -17,24 +17,9 @@ @endif -
-
New Post
-
-
- @csrf -
- - -
-
- - -
- -
-
-
+ @include('timeline.partial.new-form') +
@foreach($timeline as $item) diff --git a/resources/views/timeline/public.blade.php b/resources/views/timeline/public.blade.php index 7f5d9afd2..e5b814f1a 100644 --- a/resources/views/timeline/public.blade.php +++ b/resources/views/timeline/public.blade.php @@ -17,23 +17,8 @@
@endif -
-
New Post
-
-
- @csrf -
- - -
-
- - -
- -
-
-
+ + @include('timeline.partial.new-form')
@foreach($timeline as $item) From 35020b71084f39e170947cc92e7dc86a266533ca Mon Sep 17 00:00:00 2001 From: Stasiek Michalski Date: Sun, 3 Jun 2018 01:47:06 +0200 Subject: [PATCH 3/5] Update look of status view --- resources/views/status/show.blade.php | 129 +++++++++++++------------- 1 file changed, 63 insertions(+), 66 deletions(-) diff --git a/resources/views/status/show.blade.php b/resources/views/status/show.blade.php index 7c882def9..54d9ae030 100644 --- a/resources/views/status/show.blade.php +++ b/resources/views/status/show.blade.php @@ -2,86 +2,83 @@ @section('content') -
-
- -
-
-
-
- +
+
+
+
+ +
+
+
+
+
+ +
+
-
-
-
- -
- -
-
-
-
- {{$status->profile->username}} -

- {!! $status->rendered ?? e($status->caption) !!} -

- +
+
+
+

+ {{$status->profile->username}} + {!! $status->rendered ?? e($status->caption) !!} +

+
@foreach($status->comments->reverse()->take(10) as $item) -

- {{$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 -
-
-
-
-
+
+
+
+ @csrf - + - - @if(Auth::check()) - @if(Auth::user()->profile->id === $status->profile->id || Auth::user()->is_admin == true) -
- @csrf - - - -
- @endif - @endif - -
- @csrf - - -
-
-
- - -
-
-
+ + @if(Auth::check()) + @if(Auth::user()->profile->id === $status->profile->id || Auth::user()->is_admin == true) + + @csrf + + + +
+ @endif + @endif + +
@csrf - +
-
+
+ +
+
-@endsection \ No newline at end of file +@endsection From c4b9cc9eda1588e9787731e7a57b479bafab4b2d Mon Sep 17 00:00:00 2001 From: Stasiek Michalski Date: Sun, 3 Jun 2018 01:52:50 +0200 Subject: [PATCH 4/5] Remove useless hr --- resources/views/status/show.blade.php | 1 - 1 file changed, 1 deletion(-) diff --git a/resources/views/status/show.blade.php b/resources/views/status/show.blade.php index 54d9ae030..7e6ddc5dd 100644 --- a/resources/views/status/show.blade.php +++ b/resources/views/status/show.blade.php @@ -22,7 +22,6 @@

{{$status->created_at->diffForHumans()}}

-

From 0440f8ba720e8eab4235d1ba326c9b48d7e7c665 Mon Sep 17 00:00:00 2001 From: Stasiek Michalski Date: Sun, 3 Jun 2018 01:53:54 +0200 Subject: [PATCH 5/5] Fix #90 --- resources/assets/sass/custom.scss | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/resources/assets/sass/custom.scss b/resources/assets/sass/custom.scss index e84a5dac5..01bb1eda9 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; }