Menu

Mastering Image Optimizations in Astro (Part 1)

Images are a crucial part of any blog, but they can also be the biggest bottleneck for performance. Astro’s built-in <Image /> component handles optimization out of the box, but what if we want to add some flair?

In this post, we’ll explore how to use our custom OptimizedImage component to add hand-drawn styles, shapes, and animations to your images directly in Markdown.

1. The Basics

First, let’s look at a standard optimized image. It’s responsive and lazy-loaded by default.

A standard photo
A standard optimized image

2. Hand-Drawn Style

To fit our “Active Whiteboard” aesthetic, we can add a style="hand-drawn" prop. This adds a sketchy border and a subtle shadow.

Hand-drawn style logo
Our logo with a hand-drawn border

3. Shapes

We can also change the shape of the image. This is great for avatars or profile pictures.

Circle

Circular avatar
Perfect for avatars!

Square

Square image
A perfect square

4. Animations

Bring your content to life with entrance animations.

Fade In

Fade in animation
Fading in...

Slide Up

Slide up animation
Sliding up from below

Zoom In

Zoom in animation
Zooming in for impact

Usage

To use this in your own posts, simply use the component like this (no import needed!):

<OptimizedImage
  src="/path/to/image.jpg"
  alt="Description"
  width={500}
  height={300}
  style="hand-drawn"
  shape="rectangle"
  animation="fade-in"
  caption="Your caption here"
/>

Stay tuned for Part 2 where we explore advanced styles and 3D effects!