Process and optimize images for blog posts using ImageMagick, and add them to posts with proper components. Use when adding images, screenshots, or hero images to blog posts, or when processing image files for the blog.
Process and optimize images for blog posts with ImageMagick, then add them using the appropriate Astro components.
Apply this skill when:
CRITICAL: Choose the right component for the image type:
| Component | Use For | Interactive |
|---|---|---|
AutoOptimizedImage | Hero images only | No |
ImageLightbox | Screenshots, UI details, diagrams | Yes (click to enlarge) |
ImageLightbox is STRONGLY PREFERRED for screenshots and UI images. Users need to click and examine details closely.
AutoOptimizedImage - ONLY for hero images:
ImageLightbox - For everything else (PREFERRED):
Use ImageMagick to convert PNG to optimized JPEG (85% quality):
magick input.png -quality 85 output.jpg
Why this matters:
For new posts, create the image directory:
mkdir -p src/assets/images/blog/[slug]/
Move the processed image:
mv output.jpg src/assets/images/blog/[slug]/filename.jpg
Use descriptive filenames:
hero.jpg - for hero imagesworkflow-screenshot.jpg - descriptive names for other imagesdashboard-before.jpg, dashboard-after.jpg - for comparison shotsAdd to the MDX file's import section:
import ImageLightbox from '../../components/general/ImageLightbox.astro';
import screenshotImage from '../../assets/images/blog/[slug]/filename.jpg';
Import both components if needed:
AutoOptimizedImage - if adding hero imageImageLightbox - if adding screenshots (most common)For hero images (top of post only):
<AutoOptimizedImage src={heroImage} alt="Descriptive alt text for accessibility and SEO" loading="eager" />
For screenshots and UI images (PREFERRED):
<ImageLightbox src={screenshotImage} alt="Descriptive alt text explaining what the screenshot shows" />
Note: ImageLightbox doesn't need loading prop.
Always format the MDX file after adding images:
npx prettier --write src/content/blog/[slug].mdx
Delete original files if still present:
rm input.png # if original PNG still exists
Write descriptive alt text that:
Examples:
# 1. Convert PNG to JPEG (85% quality)
magick screenshot.png -quality 85 workflow-screenshot.jpg
# 2. Ensure directory exists
mkdir -p src/assets/images/blog/agent-skills-teaching-ai-coding-assistant/
# 3. Move processed image
mv workflow-screenshot.jpg src/assets/images/blog/agent-skills-teaching-ai-coding-assistant/
# 4. Add to MDX file (use StrReplace tool):
# - Add import: ImageLightbox component and image
# - Add component usage in appropriate location
# 5. Format with Prettier
npx prettier --write src/content/blog/agent-skills-teaching-ai-coding-assistant.mdx
# 6. Clean up
rm screenshot.png
Astro handles optimization automatically:
Never manually create multiple image sizes - ImageMagick preprocessing + Astro optimization is the complete pipeline.
ImageMagick not found:
magick --versionbrew install imagemagick (macOS)Image not displaying:
Wrong component used:
AutoOptimizedImage with loading="eager"ImageLightbox (no loading prop needed)| Task | Command |
|---|---|
| Convert PNG to JPEG | magick input.png -quality 85 output.jpg |
| Create directory | mkdir -p src/assets/images/blog/[slug]/ |
| Move image | mv output.jpg src/assets/images/blog/[slug]/ |
| Format MDX | npx prettier --write src/content/blog/[slug].mdx |