Skip to content

Commit

Permalink
resize_to_fillオプションを使用する
Browse files Browse the repository at this point in the history
  • Loading branch information
yocchan-git committed Mar 28, 2024
1 parent b37b151 commit 2f350dd
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 102 deletions.
57 changes: 0 additions & 57 deletions app/models/image_resizer.rb

This file was deleted.

5 changes: 2 additions & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class User < ApplicationRecord

authenticates_with_sorcery!
VALID_SORT_COLUMNS = %w[id login_name company_id last_activity_at created_at report comment asc desc].freeze
AVATAR_SIZE = [120, 120].freeze
RESERVED_LOGIN_NAMES = %w[adviser all graduate inactive job_seeking mentor retired student student_and_trainee trainee year_end_party].freeze
MAX_PERCENTAGE = 100
DEPRESSED_SIZE = 2
Expand Down Expand Up @@ -592,9 +593,7 @@ def avatar_url
default_image_path = '/images/users/avatars/default.png'

if avatar.attached?
options = { autorot: true, saver: { strip: true, quality: 60 } }
image_resizer = ImageResizer.new(avatar, resize_side: { width: 120, height: 120 }, options:)
image_resizer.resize.processed.url
avatar.variant(resize_to_fill: AVATAR_SIZE, autorot: true, saver: { strip: true, quality: 60 }).processed.url
else
image_url default_image_path
end
Expand Down
20 changes: 10 additions & 10 deletions test/fixtures/active_storage/blobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ company3_logo_blob: <%= ActiveStorage::Blob.fixture filename: "companies/logos/3
company4_logo_blob: <%= ActiveStorage::Blob.fixture filename: "companies/logos/4.jpg" %>

# users
hatsuno_avatar_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/hatsuno.jpg", metadata: { width: 100, height: 100 } %>
hatsuno_avatar_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/hatsuno.jpg" %>

komagata_avatar_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/komagata.jpg", metadata: { width: 100, height: 100 } %>
komagata_avatar_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/komagata.jpg" %>

machida_avatar_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/machida.jpg", metadata: { width: 100, height: 100 } %>
machida_avatar_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/machida.jpg" %>

mentormentaro_avatar_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/mentormentaro.jpg", metadata: { width: 100, height: 100 } %>
mentormentaro_avatar_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/mentormentaro.jpg" %>

mineo_avatar_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/mineo.jpg", metadata: { width: 100, height: 100 } %>
mineo_avatar_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/mineo.jpg" %>

tanaka_avatar_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/tanaka.jpg", metadata: { width: 100, height: 100 } %>
tanaka_avatar_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/tanaka.jpg" %>

yameo_avatar_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/yameo.jpg", metadata: { width: 100, height: 100 } %>
yameo_avatar_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/yameo.jpg" %>

komagata_profile_image_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/komagata.jpg", metadata: { width: 100, height: 100 } %>
komagata_profile_image_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/komagata.jpg" %>

machida_profile_image_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/machida.jpg", metadata: { width: 100, height: 100 } %>
machida_profile_image_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/machida.jpg" %>

kimuramitai_profile_image_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/default.jpg", metadata: { width: 100, height: 100 } %>
kimuramitai_profile_image_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/default.jpg" %>
32 changes: 0 additions & 32 deletions test/models/image_resizer_test.rb

This file was deleted.

0 comments on commit 2f350dd

Please sign in to comment.