| name | img |
|---|---|
| description | Use this skill when the user runs /img or asks to process, optimize, or convert images for their Rails app. Converts PNG exports from Sketch (or any PNG) to WebP using cwebp, places the result in app/assets/images/, and outputs the ready-to-use image_tag ERB snippet. Triggers on /img <filename>, "process this image", "convert to webp", "optimize this PNG for Rails". |
Converts a PNG to WebP and outputs the Rails image_tag ERB snippet.
- Accepts a PNG filename (or path) and optional display width
- Checks that
cwebpis available - Converts the PNG to WebP at quality 85
- The destination output will be the same path as the original png
- Outputs the
image_tagERB snippet
/img <filename_or_path> [display_width_px]
Examples:
/img hero-illustration.png/img ~/Desktop/exports/onboarding-step1.png 400/img exports/ 600(batch — all PNGs in a directory)
Extract:
input— file path or directorydisplay_width— optional integer (px). If omitted, look at the dimensions of the png and divide by 2. The originals are 2x their desired size.
which cwebpIf missing, tell the user to install it:
- macOS:
brew install webp - Ubuntu:
sudo apt install webp
Then stop.
Look for config/application.rb walking up from the current directory. The assets destination is <rails_root>/app/assets/images/.
If no Rails root found, output the WebP in the same directory as the source and warn the user.
Single file:
cwebp -q 85 "<input.png>" -o "app/assets/images/<name>.webp"Batch (directory):
for f in <dir>/*.png; do
name=$(basename "$f" .png)
cwebp -q 85 "$f" -o "app/assets/images/${name}.webp"
doneStrip any @2x suffix from the output filename — e.g. hero@2x.png → hero.webp.
For each converted file, print:
<%= image_tag "filename.webp", alt: "" %>If display_width was provided:
<%= image_tag "filename.webp", alt: "", width: 400 %>Analyze the image to generate the alt text.
Print a short summary:
- Original file size
- WebP file size
- % reduction
- Destination path
- Quality 85 is a good default. If the user wants to adjust, accept
-q <value>as an optional flag. - Do not convert if the output WebP already exists and is newer than the source PNG, unless the user passes
--force. - The skill assumes PNGs are exported at 2x from Sketch. It does not rescale — sizing is handled via CSS.