From cd263138087e3cb5301b523d79795f6a9250983a Mon Sep 17 00:00:00 2001 From: songtianlun Date: Wed, 5 Feb 2025 14:53:54 +0800 Subject: [PATCH] chore: update dependencies in Dockerfile and Gemfile - Remove unused `ruby-vips` gem from Gemfile - Update Dockerfile to remove `libvips42` package, which is no longer needed - Comment out legacy watermarking code in `AddWatermarkToWeatherArtWorker` These changes streamline the dependencies, making the project lighter and reduce potential security issues with unused gems and packages. The watermarking functionality is now commented out for potential future use but is not currently needed. --- Dockerfile | 2 +- Gemfile | 2 +- Gemfile.lock | 1 - .../add_watermark_to_weather_art_worker.rb | 44 +++++++++---------- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7e3ddf0..69e505b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,7 @@ WORKDIR /rails # Install base packages RUN apt-get update -qq && \ - apt-get install --no-install-recommends -y curl libjemalloc2 libvips sqlite3 libpq5 redis-tools libvips42 && \ + apt-get install --no-install-recommends -y curl libjemalloc2 libvips sqlite3 libpq5 redis-tools && \ rm -rf /var/lib/apt/lists /var/cache/apt/archives # Set production environment diff --git a/Gemfile b/Gemfile index 6d61b7d..76d9bc5 100644 --- a/Gemfile +++ b/Gemfile @@ -61,7 +61,7 @@ gem "sidekiq", "~> 7.3" gem "sidekiq-scheduler", "~> 5.0" gem "image_processing", "~> 1.13" -gem "ruby-vips", "~> 2.2" +# gem "ruby-vips", "~> 2.2" gem "mini_magick", "~> 4.13.2" group :development, :test do diff --git a/Gemfile.lock b/Gemfile.lock index d03e2f7..3c8750f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -534,7 +534,6 @@ DEPENDENCIES rails (~> 8.0.1) rubocop-rails-omakase ruby-openai (~> 7.3) - ruby-vips (~> 2.2) selenium-webdriver sidekiq (~> 7.3) sidekiq-scheduler (~> 5.0) diff --git a/app/workers/add_watermark_to_weather_art_worker.rb b/app/workers/add_watermark_to_weather_art_worker.rb index 6f27610..ed166ac 100644 --- a/app/workers/add_watermark_to_weather_art_worker.rb +++ b/app/workers/add_watermark_to_weather_art_worker.rb @@ -18,33 +18,33 @@ class AddWatermarkToWeatherArtWorker def add_watermark return if weather_art.image_with_watermark.attached? - watermark_path = Rails.root.join("app/assets/images/today_ai_weather_copyright_watermark1.png") - return unless File.exist?(watermark_path) + # watermark_path = Rails.root.join("app/assets/images/today_ai_weather_copyright_watermark1.png") + # return unless File.exist?(watermark_path) - image_tempfile = nil - watermark_tempfile = nil - begin - image_tempfile = weather_art.image.download - return unless image_dimensions_are_sufficient?(image_tempfile.path) + # image_tempfile = nil + # watermark_tempfile = nil + # begin + # image_tempfile = weather_art.image.download + # return unless image_dimensions_are_sufficient?(image_tempfile.path) - image = ImageProcessing::Vips.source(image_tempfile.path) - watermark = ImageProcessing::Vips.source(watermark_path) - watermarked_image = image.composite(watermark, "overlay") - watermark_tempfile = Tempfile.new([ "watermarked_image", ".png" ]) - watermarked_image.write_to_file(watermark_tempfile.path) - weather_art.image_with_watermark.attach( - io: File.open(watermark_tempfile.path), - filename: "#{generate_filename("watermarked")}", - content_type: "image/png" - ) - ensure - watermark_tempfile.unlink if watermark_tempfile - end + # image = ImageProcessing::Vips.source(image_tempfile.path) + # watermark = ImageProcessing::Vips.source(watermark_path) + # watermarked_image = image.composite(watermark, "overlay") + # watermark_tempfile = Tempfile.new([ "watermarked_image", ".png" ]) + # watermarked_image.write_to_file(watermark_tempfile.path) + # weather_art.image_with_watermark.attach( + # io: File.open(watermark_tempfile.path), + # filename: "#{generate_filename("watermarked")}", + # content_type: "image/png" + # ) + # ensure + # watermark_tempfile.unlink if watermark_tempfile + # end end def image_dimensions_are_sufficient?(image_path) - dimensions = ImageProcessing::Vips.source(image_path).sizes - dimensions.width >= 200 && dimensions.height >= 200 + # dimensions = ImageProcessing::Vips.source(image_path).sizes + # dimensions.width >= 200 && dimensions.height >= 200 end def generate_filename(prefix)