posts: remove cropped thumbnails.

This commit is contained in:
evazion
2021-12-16 15:54:26 -06:00
parent 379775d10d
commit 1c5786d20f
10 changed files with 7 additions and 62 deletions

View File

@@ -181,17 +181,6 @@ class MediaFile
nil
end
# Return a cropped preview version of the file, sized to fit exactly within
# the given width and height.
#
# @param width [Integer] the width of the cropped image
# @param height [Integer] the height of the cropped image
# @param options [Hash] extra options when generating the preview
# @return [MediaFile] a cropped preview file
def crop(width, height, **options)
nil
end
def attributes
{
path: path,

View File

@@ -92,10 +92,6 @@ class MediaFile::Image < MediaFile
resize(w, h, size: :force, **options)
end
def crop(max_width, max_height, **options)
resize(max_width, max_height, crop: :attention, **options)
end
def preview_frame
if is_animated?
FFmpeg.new(file).smart_video_preview

View File

@@ -30,10 +30,6 @@ class MediaFile::Ugoira < MediaFile
preview_frame.preview(width, height, **options)
end
def crop(width, height)
preview_frame.crop(width, height)
end
def duration
(frame_delays.sum / 1000.0)
end

View File

@@ -15,10 +15,6 @@ class MediaFile::Video < MediaFile
preview_frame.preview(max_width, max_height, **options)
end
def crop(max_width, max_height)
preview_frame.crop(max_width, max_height)
end
private
def video

View File

@@ -84,7 +84,6 @@ class UploadService
def convert_to_post(upload)
Post.new.tap do |p|
p.has_cropped = true
p.tag_string = upload.tag_string
p.md5 = upload.md5
p.file_ext = upload.file_ext

View File

@@ -3,7 +3,7 @@
class MediaAsset < ApplicationRecord
class Error < StandardError; end
VARIANTS = %i[preview crop 180x180 360x360 720x720 sample original]
VARIANTS = %i[preview 180x180 360x360 720x720 sample original]
ENABLE_SEO_POST_URLS = Danbooru.config.enable_seo_post_urls
LARGE_IMAGE_WIDTH = Danbooru.config.large_image_width
STORAGE_SERVICE = Danbooru.config.storage_manager
@@ -71,8 +71,6 @@ class MediaAsset < ApplicationRecord
media_file.preview(width, height, format: :jpeg, quality: 85)
in :"720x720"
media_file.preview(width, height, format: :webp, quality: 75)
in :crop
media_file.crop(width, height)
in :sample if media_asset.is_ugoira?
media_file.convert
in :sample if media_asset.is_static_image?
@@ -87,7 +85,7 @@ class MediaAsset < ApplicationRecord
end
def file_path(slug = "")
if variant.in?(%i[preview crop 180x180 360x360 720x720]) && media_asset.is_flash?
if variant.in?(%i[preview 180x180 360x360 720x720]) && media_asset.is_flash?
"/images/download-preview.png"
else
slug = "__#{slug}__" if slug.present?
@@ -109,7 +107,7 @@ class MediaAsset < ApplicationRecord
# The file extension of this variant.
def file_ext
case variant
when :preview, :crop, :"180x180", :"360x360"
when :preview, :"180x180", :"360x360"
"jpg"
when :"720x720"
"webp"
@@ -124,8 +122,6 @@ class MediaAsset < ApplicationRecord
case variant
when :preview
[150, 150]
when :crop
[150, 150]
when :"180x180"
[180, 180]
when :"360x360"
@@ -140,12 +136,7 @@ class MediaAsset < ApplicationRecord
end
def dimensions
case variant
when :crop
max_dimensions
else
MediaFile.scale_dimensions(media_asset.image_width, media_asset.image_height, max_dimensions[0], max_dimensions[1])
end
MediaFile.scale_dimensions(media_asset.image_width, media_asset.image_height, max_dimensions[0], max_dimensions[1])
end
def width
@@ -160,8 +151,6 @@ class MediaAsset < ApplicationRecord
case variant
when :preview
true
when :crop
true
when :"180x180"
true
when :"360x360"

View File

@@ -117,10 +117,6 @@ class Post < ApplicationRecord
media_asset.variant(:preview).file_url
end
def crop_file_url
media_asset.variant(:crop).file_url
end
def open_graph_image_url
if is_image?
if has_large?
@@ -1183,7 +1179,7 @@ class Post < ApplicationRecord
def purge_cached_urls!
urls = [
preview_file_url, crop_file_url, large_file_url, file_url,
preview_file_url, large_file_url, file_url,
tagged_file_url(tagged_filenames: true), tagged_large_file_url(tagged_filenames: true),
]
@@ -1286,7 +1282,7 @@ class Post < ApplicationRecord
include PixivMethods
include ValidationMethods
has_bit_flags ["has_embedded_notes", "has_cropped"]
has_bit_flags ["has_embedded_notes"]
def safeblocked?
CurrentUser.safe_mode? && (rating != "s" || Danbooru.config.safe_mode_restricted_tags.any? { |tag| tag.in?(tag_array) })

View File

@@ -49,7 +49,7 @@ class UserPolicy < ApplicationPolicy
new_post_navigation_layout enable_private_favorites
hide_deleted_posts style_usernames show_deleted_children
disable_categorized_saved_searches disable_tagged_filenames
disable_cropped_thumbnails disable_mobile_gestures enable_safe_mode
disable_mobile_gestures enable_safe_mode
enable_desktop_mode disable_post_tooltips
].compact
end

View File

@@ -98,7 +98,6 @@ namespace :danbooru do
posts.parallel_each do |post|
sm.store_file(post.file(:preview), post, :preview) if post.has_preview?
sm.store_file(post.file(:crop), post, :crop) if post.has_cropped?
sm.store_file(post.file(:sample), post, :sample) if post.has_large?
sm.store_file(post.file(:original), post, :original)
end

View File

@@ -140,20 +140,6 @@ class MediaFileTest < ActiveSupport::TestCase
end
end
context "#crop" do
should "generate a cropped preview image" do
assert_equal([150, 150], MediaFile.open("test/files/test.jpg").crop(150, 150).dimensions)
assert_equal([150, 150], MediaFile.open("test/files/test.png").crop(150, 150).dimensions)
assert_equal([150, 150], MediaFile.open("test/files/test.gif").crop(150, 150).dimensions)
end
should "generate a cropped preview image for a video" do
skip unless MediaFile.videos_enabled?
assert_equal([150, 150], MediaFile.open("test/files/test-512x512.webm").crop(150, 150).dimensions)
assert_equal([150, 150], MediaFile.open("test/files/test-300x300.mp4").crop(150, 150).dimensions)
end
end
context "for a ugoira" do
setup do
skip unless MediaFile::Ugoira.videos_enabled?
@@ -163,7 +149,6 @@ class MediaFileTest < ActiveSupport::TestCase
should "generate a preview" do
assert_equal([60, 60], @ugoira.preview(150, 150).dimensions)
assert_equal([150, 150], @ugoira.crop(150, 150).dimensions)
end
should "get the duration" do