diff options
author | ThibG <thib@sitedethib.com> | 2018-07-30 16:51:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-30 16:51:55 +0200 |
commit | ce090a5201aceaab9a5c9621a6cdb3c7beefcc40 (patch) | |
tree | 8727c7f3f289fa29051a31df67d6dc8d5c60e422 | |
parent | b02bfe86ce26ef001420841673257c9c5326b45c (diff) | |
parent | 5f1bdca4c8c3f34e0cc8f6ed3b6a264f42cc8ed2 (diff) |
Merge pull request #614 from ThibG/glitch-soc/merge-upstream
Merge upstream changes up to (excluding) profile redesign
-rw-r--r-- | app/javascript/mastodon/locales/pl.json | 2 | ||||
-rw-r--r-- | app/javascript/mastodon/utils/resize_image.js | 18 | ||||
-rw-r--r-- | app/models/media_attachment.rb | 6 | ||||
-rw-r--r-- | config/locales/pl.yml | 1 | ||||
-rw-r--r-- | lib/paperclip/lazy_thumbnail.rb | 13 | ||||
-rw-r--r-- | spec/models/media_attachment_spec.rb | 6 |
6 files changed, 22 insertions, 24 deletions
diff --git a/app/javascript/mastodon/locales/pl.json b/app/javascript/mastodon/locales/pl.json index 81b829a2f..67711d1bd 100644 --- a/app/javascript/mastodon/locales/pl.json +++ b/app/javascript/mastodon/locales/pl.json @@ -141,7 +141,7 @@ "keyboard_shortcuts.hotkey": "Klawisz", "keyboard_shortcuts.legend": "aby wyświetlić tą legendę", "keyboard_shortcuts.mention": "aby wspomnieć o autorze", - "keyboard_shortcuts.profile": "to open author's profile", + "keyboard_shortcuts.profile": "aby przejść do profilu autora wpisu", "keyboard_shortcuts.reply": "aby odpowiedzieć", "keyboard_shortcuts.search": "aby przejść do pola wyszukiwania", "keyboard_shortcuts.toggle_hidden": "aby wyświetlić lub ukryć wpis spod CW", diff --git a/app/javascript/mastodon/utils/resize_image.js b/app/javascript/mastodon/utils/resize_image.js index 279a858ca..d1608094f 100644 --- a/app/javascript/mastodon/utils/resize_image.js +++ b/app/javascript/mastodon/utils/resize_image.js @@ -1,6 +1,6 @@ import EXIF from 'exif-js'; -const MAX_IMAGE_DIMENSION = 1280; +const MAX_IMAGE_PIXELS = 1638400; // 1280x1280px const getImageUrl = inputFile => new Promise((resolve, reject) => { if (window.URL && URL.createObjectURL) { @@ -73,18 +73,8 @@ const processImage = (img, { width, height, orientation, type = 'image/png' }) = const resizeImage = (img, type = 'image/png') => new Promise((resolve, reject) => { const { width, height } = img; - let newWidth, newHeight; - - if (width > height) { - newHeight = height * MAX_IMAGE_DIMENSION / width; - newWidth = MAX_IMAGE_DIMENSION; - } else if (height > width) { - newWidth = width * MAX_IMAGE_DIMENSION / height; - newHeight = MAX_IMAGE_DIMENSION; - } else { - newWidth = MAX_IMAGE_DIMENSION; - newHeight = MAX_IMAGE_DIMENSION; - } + const newWidth = Math.round(Math.sqrt(MAX_IMAGE_PIXELS * (width / height))); + const newHeight = Math.round(Math.sqrt(MAX_IMAGE_PIXELS * (height / width))); getOrientation(img, type) .then(orientation => processImage(img, { @@ -104,7 +94,7 @@ export default inputFile => new Promise((resolve, reject) => { } loadImage(inputFile).then(img => { - if (img.width < MAX_IMAGE_DIMENSION && img.height < MAX_IMAGE_DIMENSION) { + if (img.width * img.height < MAX_IMAGE_PIXELS) { resolve(inputFile); return; } diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index c041dce51..07c08d63a 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -34,12 +34,12 @@ class MediaAttachment < ApplicationRecord IMAGE_STYLES = { original: { - geometry: '1280x1280>', + pixels: 1_638_400, # 1280x1280px file_geometry_parser: FastGeometryParser, }, small: { - geometry: '400x400>', + pixels: 160_000, # 400x400px file_geometry_parser: FastGeometryParser, }, }.freeze @@ -176,7 +176,7 @@ class MediaAttachment < ApplicationRecord elsif AUDIO_MIME_TYPES.include? f.file_content_type [:audio_transcoder] else - [:thumbnail] + [:lazy_thumbnail] end end end diff --git a/config/locales/pl.yml b/config/locales/pl.yml index cf0d786a7..d79bfd0a8 100644 --- a/config/locales/pl.yml +++ b/config/locales/pl.yml @@ -223,6 +223,7 @@ pl: space: Używana powierzchnia title: Panel administracyjny total_users: łącznie użytkowników + trends: Na czasie week_interactions: interakcje w tym tygodniu week_users_active: aktywni w tym tygodniu week_users_new: rejestracje w tym tygodniu diff --git a/lib/paperclip/lazy_thumbnail.rb b/lib/paperclip/lazy_thumbnail.rb index aafa21343..ea675a5bf 100644 --- a/lib/paperclip/lazy_thumbnail.rb +++ b/lib/paperclip/lazy_thumbnail.rb @@ -5,8 +5,14 @@ module Paperclip def make return File.open(@file.path) unless needs_convert? - min_side = [@current_geometry.width, @current_geometry.height].min - options[:geometry] = "#{min_side.to_i}x#{min_side.to_i}#" if @target_geometry.square? && min_side < @target_geometry.width + if options[:geometry] + min_side = [@current_geometry.width, @current_geometry.height].min.to_i + options[:geometry] = "#{min_side}x#{min_side}#" if @target_geometry.square? && min_side < @target_geometry.width + elsif options[:pixels] + width = Math.sqrt(options[:pixels] * (@current_geometry.width.to_f / @current_geometry.height.to_f)).round.to_i + height = Math.sqrt(options[:pixels] * (@current_geometry.height.to_f / @current_geometry.width.to_f)).round.to_i + options[:geometry] = "#{width}x#{height}>" + end Paperclip::Thumbnail.make(file, options, attachment) end @@ -18,7 +24,8 @@ module Paperclip end def needs_different_geometry? - !@target_geometry.nil? && @current_geometry.width != @target_geometry.width && @current_geometry.height != @target_geometry.height + (options[:geometry] && @current_geometry.width != @target_geometry.width && @current_geometry.height != @target_geometry.height) || + (options[:pixels] && @current_geometry.width * @current_geometry.height > options[:pixels]) end def needs_different_format? diff --git a/spec/models/media_attachment_spec.rb b/spec/models/media_attachment_spec.rb index d2230b6d0..cb1cee518 100644 --- a/spec/models/media_attachment_spec.rb +++ b/spec/models/media_attachment_spec.rb @@ -129,9 +129,9 @@ RSpec.describe MediaAttachment, type: :model do expect(media.file.meta["original"]["width"]).to eq 600 expect(media.file.meta["original"]["height"]).to eq 400 expect(media.file.meta["original"]["aspect"]).to eq 1.5 - expect(media.file.meta["small"]["width"]).to eq 400 - expect(media.file.meta["small"]["height"]).to eq 267 - expect(media.file.meta["small"]["aspect"]).to eq 400.0/267 + expect(media.file.meta["small"]["width"]).to eq 490 + expect(media.file.meta["small"]["height"]).to eq 327 + expect(media.file.meta["small"]["aspect"]).to eq 490.0/327 end end |