Skip to content

Instantly share code, notes, and snippets.

@JudahSan
Created April 2, 2024 15:41
Show Gist options
  • Save JudahSan/6e6145538d54ca6553d653f26132cdcf to your computer and use it in GitHub Desktop.
Save JudahSan/6e6145538d54ca6553d653f26132cdcf to your computer and use it in GitHub Desktop.
ActiveStorage::Variant on RoR 7: vips

Problem:

  • The application crashed when attempting to resize the image to a size of 50px x 50px.
  • ActiveStorage was properly configured with the required dependencies.
def image_as_thumbnail
    image.variant(resize_to_limit: [50, 50]).processed
end
<td class="py-4 px-6 text-sm font-medium text-purple-500 whitespace-nowrap dark:text-white">
     <%= c.image.present? ? image_tag(c.image_as_thumbnail) : image_tag("https://via.placeholder.com/50") %>
</td>
  • The following error message occurred when running the app:
| LoadError (Could not open library 'vips.so.42': vips.so.42: cannot open shared object file: No such file or directory.
17:41:13 web.1  | Could not open library 'libvips.so.42': libIlmImf-2_5.so.25: cannot open shared object file: No such file or directory.
17:41:13 web.1  | Searched in <system library path>, /usr/lib, /usr/local/lib, /opt/local/lib):
17:41:13 web.1  |   
  • Libvips was already installed.

  • Installed the missing dependencies:

sudo apt-get install libopenexr-dev
  • Received the following error message:
The following packages have unmet dependencies:
 libopenexr-dev : Depends: libopenexr25 (= 2.5.7-1ubuntu0.1~esm1) but 2.5.8-0ubuntu1~22.04.sav1 is to be installed
E: Unable to correct problems, you have held broken packages.

Solution:

  • Checked for conflicting packages:
sudo apt-mark showhold
  • Found no held packages.

  • Installed ImageMagick:

sudo apt-get install imagemagick
  • Downgraded to libopenexr25:
sudo apt-get install libopenexr25=2.5.7-1ubuntu0.1~esm1
  • Installed libopenexr:
sudo apt-get install libopenexr-dev
  • Fixed broken packages:
sudo apt-get install -f
  • Reinstalled libopenexr:
sudo apt-get install libopenexr-dev

Following these steps resolved the issue with libopenexr and ensured that libvips could be used successfully for image resizing within the Rails ActiveStorage environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment