From 87ee410ce18857bc6c9927c1b29bcb57df338cd2 Mon Sep 17 00:00:00 2001 From: yocchan-git Date: Sat, 17 Feb 2024 13:10:14 +0900 Subject: [PATCH 1/2] =?UTF-8?q?ImageMagick=E3=81=8B=E3=82=89libvips?= =?UTF-8?q?=E3=81=AB=E7=A7=BB=E8=A1=8C=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .circleci/config.yml | 3 +++ .devcontainer/Dockerfile | 2 +- Dockerfile | 4 ++-- app/models/article.rb | 4 ++-- app/models/book.rb | 4 ++-- app/models/company.rb | 4 ++-- app/models/user.rb | 4 ++-- app/models/work.rb | 4 ++-- app/views/admin/users/show.html.slim | 2 +- app/views/articles/_recent_articles.html.slim | 2 +- app/views/mentor/practices/_form.html.slim | 4 ++-- config/application.rb | 1 + 12 files changed, 21 insertions(+), 17 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6bbf74b5b22..1c83f8ffb06 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -75,6 +75,9 @@ jobs: - run: name: Install japanese font command: sudo apt-get install -y fonts-noto-cjk + - run: + name: Install libvips + command: sudo apt-get install -y libvips - run: name: Wait for DB command: 'dockerize -wait tcp://localhost:5432 -timeout 1m' diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 53168b09624..cc7ce7fdb7e 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -10,7 +10,7 @@ RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/ # Install OS packages RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ - && apt-get -y install --no-install-recommends imagemagick pngcrush optipng gsfonts + && apt-get -y install --no-install-recommends libvips42 libvips-dev pngcrush optipng gsfonts # Install bundler RUN gem install --no-document bundler -v 2.2.27 diff --git a/Dockerfile b/Dockerfile index e3c00156cf5..36ab275048b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,8 +19,8 @@ RUN apk add --no-cache \ tzdata && \ cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime -# ImageMagick -RUN apk add --no-cache imagemagick imagemagick-heic imagemagick-jpeg imagemagick-pdf imagemagick-svg imagemagick-webp bash pngcrush optipng=0.7.8-r0 ghostscript-fonts +# libvips +RUN apk add --no-cache vips-dev orc-dev bash pngcrush optipng=0.7.8-r0 ghostscript-fonts # Install npm packages COPY package.json yarn.lock ./ diff --git a/app/models/article.rb b/app/models/article.rb index 63231f334c7..d38f03c038a 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -20,7 +20,7 @@ class Article < ApplicationRecord belongs_to :user include ActionView::Helpers::AssetUrlHelper - THUMBNAIL_SIZE = '1200x630>' + THUMBNAIL_SIZE = [1200, 630].freeze has_one_attached :thumbnail before_validation :set_published_at, if: :will_be_published? @@ -38,7 +38,7 @@ class Article < ApplicationRecord def prepared_thumbnail_url if thumbnail.attached? - thumbnail.variant(resize: THUMBNAIL_SIZE).processed.url + thumbnail.variant(resize_to_limit: THUMBNAIL_SIZE).processed.url else image_url('/images/articles/thumbnails/blank.svg') end diff --git a/app/models/book.rb b/app/models/book.rb index 57449766552..797c0002f7c 100644 --- a/app/models/book.rb +++ b/app/models/book.rb @@ -3,7 +3,7 @@ class Book < ApplicationRecord include ActionView::Helpers::AssetUrlHelper - COVER_SIZE = '100x150>' + COVER_SIZE = [100, 150].freeze has_many :practices_books, dependent: :destroy has_many :practices, through: :practices_books has_one_attached :cover @@ -17,7 +17,7 @@ class Book < ApplicationRecord def cover_url default_image_path = '/images/books/covers/default.svg' if cover.attached? - cover.variant(resize: COVER_SIZE).processed.url + cover.variant(resize_to_limit: COVER_SIZE).processed.url else image_url default_image_path end diff --git a/app/models/company.rb b/app/models/company.rb index d756a99186e..5602d5d828a 100644 --- a/app/models/company.rb +++ b/app/models/company.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class Company < ApplicationRecord - LOGO_SIZE = '88x88>' + LOGO_SIZE = [88, 88].freeze has_many :users, dependent: :nullify validates :name, presence: true has_one_attached :logo @@ -10,7 +10,7 @@ class Company < ApplicationRecord def logo_url if logo.attached? - logo.variant(resize: LOGO_SIZE).processed.url + logo.variant(resize_to_limit: LOGO_SIZE).processed.url else image_url('/images/companies/logos/default.png') end diff --git a/app/models/user.rb b/app/models/user.rb index 3bb2fbd68fd..eb1a08d0a04 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -7,7 +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 = '88x88>' + AVATAR_SIZE = [88, 88].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 @@ -592,7 +592,7 @@ def avatar_url default_image_path = '/images/users/avatars/default.png' if avatar.attached? - avatar.variant(resize: AVATAR_SIZE).processed.url + avatar.variant(resize_to_limit: AVATAR_SIZE).processed.url else image_url default_image_path end diff --git a/app/models/work.rb b/app/models/work.rb index ec83e12dfe0..35414480131 100644 --- a/app/models/work.rb +++ b/app/models/work.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class Work < ApplicationRecord - THUMBNAIL_SIZE = '1200x630>' + THUMBNAIL_SIZE = [1200, 630].freeze belongs_to :user has_one_attached :thumbnail @@ -15,7 +15,7 @@ class Work < ApplicationRecord def thumbnail_url if thumbnail.attached? - thumbnail.variant(resize: THUMBNAIL_SIZE).processed.url + thumbnail.variant(resize_to_limit: THUMBNAIL_SIZE).processed.url else image_url('/images/works/thumbnails/default.png') end diff --git a/app/views/admin/users/show.html.slim b/app/views/admin/users/show.html.slim index 4a125c9d995..a34fce26103 100644 --- a/app/views/admin/users/show.html.slim +++ b/app/views/admin/users/show.html.slim @@ -1 +1 @@ -= image_tag @user.avatar.variant(resize: '88x88>').processed.url += image_tag @user.avatar.variant(resize_to_limit: [88, 88]).processed.url diff --git a/app/views/articles/_recent_articles.html.slim b/app/views/articles/_recent_articles.html.slim index 0566d85c9c9..39d8cdbe9c3 100644 --- a/app/views/articles/_recent_articles.html.slim +++ b/app/views/articles/_recent_articles.html.slim @@ -11,7 +11,7 @@ .card-list-item__thumbnail .card-list-item__thumbnail-inner - if recent_article.thumbnail.attached? - = image_tag recent_article.thumbnail.variant(resize: '200x105>').processed.url, class: 'card-list-item__thumbnail-image', alt: "ブログ記事「#{recent_article.title}」のアイキャッチ画像" + = image_tag recent_article.thumbnail.variant(resize_to_limit: [200, 105]).processed.url, class: 'card-list-item__thumbnail-image', alt: "ブログ記事「#{recent_article.title}」のアイキャッチ画像" - else = image_tag 'work-blank.svg', class: 'card-list-item__thumbnail-image', alt: 'ブログ記事のブランクアイキャッチ画像' .card-list-item__rows diff --git a/app/views/mentor/practices/_form.html.slim b/app/views/mentor/practices/_form.html.slim index 3ece7399736..9ead0b1a1f2 100644 --- a/app/views/mentor/practices/_form.html.slim +++ b/app/views/mentor/practices/_form.html.slim @@ -20,7 +20,7 @@ .form-item-file-input.js-file-input.a-file-input label.js-file-input__preview(for='practice_ogp_image') - if f.object.ogp_image.attached? - = image_tag f.object.ogp_image.variant(resize: '100x100') + = image_tag f.object.ogp_image.variant(resize_to_limit: [100, 100]) p 画像を変更 - else p 画像を選択 @@ -108,7 +108,7 @@ .form-item-file-input.js-file-input.a-file-input label.js-file-input__preview(for='practice_completion_image') - if f.object.completion_image.attached? - = image_tag f.object.completion_image.variant(resize: '100x100') + = image_tag f.object.completion_image.variant(resize_to_limit: [100, 100]) p 画像を変更 - else p 画像を選択 diff --git a/config/application.rb b/config/application.rb index c00a3637cfe..20cc4ad624c 100644 --- a/config/application.rb +++ b/config/application.rb @@ -28,5 +28,6 @@ class Application < Rails::Application end config.active_storage.resolve_model_to_route = :rails_storage_proxy + config.active_storage.variant_processor = :vips end end From c35544cb1ef13f4e2e42fb7a7e473558e334ae1a Mon Sep 17 00:00:00 2001 From: yocchan-git Date: Sat, 24 Feb 2024 09:58:10 +0900 Subject: [PATCH 2/2] =?UTF-8?q?check=E3=81=AB=E3=82=82libvips=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .circleci/config.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1c83f8ffb06..4faee37acc6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -28,6 +28,12 @@ jobs: - run: name: Slim Lint command: bundle exec slim-lint app/views -c config/slim_lint.yml + - run: + name: Update package list + command: sudo apt-get update + - run: + name: Install libvips + command: sudo apt-get install -y libvips - run: name: Traceroute command: FAIL_ON_ERROR=1 bundle exec rake traceroute