Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • React Tutorial
  • React Exercise
  • React Basic Concepts
  • React Components
  • React Props
  • React Hooks
  • React Router
  • React Advanced
  • React Examples
  • React Interview Questions
  • React Projects
  • Next.js Tutorial
  • React Bootstrap
  • React Material UI
  • React Ant Design
  • React Desktop
  • React Rebass
  • React Blueprint
  • JavaScript
  • Web Technology
Open In App
Next Article:
Gatsby Images
Next article icon

Gatsby Images

Last Updated : 01 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Gatsby is a free and open-source framework based on React that helps developers build blazing-fast websites and apps. Gatsby sites are fully functional React apps, so you can create dynamic web applications that are fast, responsive, and secure.

Using images is a challenge on any website. To use them for great performance across devices, you need multiple sizes and resolutions of each image. Luckily, Gatsby has several useful plugins to do so.

Create a new Gatsby Application

Step 1: Run the below code in the terminal to create a new gatsby site.

npm init gatsby

Give the name 'gfg' to the application project.

Step 2: Move to the new 'gfg' folder using the below command.

cd gfg

Project Structure:

 

Handling Images in Gatsby

It is very difficult to handle the responsiveness and quality of images in any framework, but in gatsby, we have a plugin that we can use to handle images very easily.  To use the plugin, follow the below steps.

Step 1: Install the plugin using the below command in the terminal:

npm install gatsby-plugin-image gatsby-plugin-sharp gatsby-source-filesystem gatsby-transformer-sharp

Step 2: Add the plugins to your gatsby-config.js file:

JavaScript
require("dotenv").config({   path: `.env.${process.env.NODE_ENV}`, }) module.exports = {   siteMetadata: {     siteUrl: `https://www.yourdomain.tld`,   },      plugins: [     `gatsby-plugin-image`,     `gatsby-plugin-sharp`,     `gatsby-transformer-sharp`,   ], } 

Step 3: Use the plugin to display images. For this, add the below code in your index.js file. We are loading a demo image with the name 'logo.png'.

JavaScript
import * as React from "react" import { StaticImage } from "gatsby-plugin-image"  const IndexPage = () => {   return (     <main >       <h3>GeeksforGeeks - Below is the image</h3>       <StaticImage src="logo.png" alt="Demo Image" />     </main>   ) }  export default IndexPage; 

Run the application: Use the below code in the terminal to start the application.

npm run develop

Output:


Next Article
Gatsby Images

I

imranalam21510
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • ReactJS
  • Gatsby

Similar Reads

    Gatsby Styles
    Gatsby lets you fashion your additives and pages with the use of various strategies, offering flexibility in the way you cope with CSS and styling to your undertaking. This can range from conventional CSS files to fashionable CSS-in-JS libraries. we will discuss how can we add styles to the Gatsby a
    3 min read
    Blaze UI Images
    Blaze UI is a free open source UI Toolkit that provides a great structure for building websites quickly with a scalable and maintainable foundation. All components in Blaze UI are developed mobile-first and rely solely on native browser features, not a separate library or framework. It helps us to c
    2 min read
    Blaze UI Image Attributes
    Blaze UI is a CSS open-source framework. It is a lightweight UI toolkit and provides great tools for building customized and scalable applications. It can work with any framework that exists. It can adapt to any ecosystem. All designs or CSS are mobile-first and hence responsive. Its project is avai
    2 min read
    Gatsby Introduction
    Gatsby is a free, open-source framework built on React that empowers developers to create blazing-fast websites and apps. Gatsby sites are fully functional React applications, enabling the development of dynamic, responsive, and secure web applications. It uses various optimization techniques, such
    2 min read
    Node Jimp | Gaussian
    The Gaussian() function is an inbuilt function in Nodejs | Jimp that applies a true Gaussian blur to the image but its processing is quite slow in comparison to other Jimp functions.  Syntax:  gaussian(r, cb) Parameter:  r: This parameter stores the pixel radius of the blur.cb: This is an optional p
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences