"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to use Unsplash Images in your code

How to use Unsplash Images in your code

Published on 2024-11-02
Browse:897

As a developer working on a new SaaS project, I needed to link some Unsplash images directly through their URLs.
Initially, I came across an article (link) recommending the use of the https://source.unsplash.com/ API. However, this method no longer works, and simply copying the link from the URL field didn't provide the direct image URL needed for embedding.

https://unsplash.com/photos/a-digital-illustration-of-the-letter-k-CnbzJXw5Hx4
How to use Unsplash Images in your code

Unsplash Image URLs

The next option I tried was copying the image URL by right-clicking on it. However, this URL was filled with unnecessary parameters that I didn't need, requiring manual removal every time. For example:

https://images.unsplash.com/photo-1725610588086-b9e38da987f7?q=80&w=3500&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA==

As a lazy developer who values efficiency, I found this process frustrating. I didn't want to manually clean up URLs every time I wanted to use an image.

The Lightbulb Moment: Building my first Chrome Extension

So, after wasting way too much time doing this manually, I did what any lazy developer with an aversion to repetitive tasks would do—I built a Chrome extension. Introducing "CopySplash", the Chrome extension you never knew you needed but now can't live without!

And the best part? It’s an open-source project! (GitHub) Feel free to dive into the code, contribute, suggest features, or even just tell me how much you love it or not?. Compliments are always appreciated.

What Does "CopySplash" Do?

  • Provides a convenient "Copy Link" button overlay on Unsplash images, allowing users to quickly copy the image URL to their clipboard with a single click.

How to use Unsplash Images in your code

  • Set custom parameters to adjust the size, quality, cropping, and more, tailored to your specific needs and save them.

How to use Unsplash Images in your code

But Wait… What’s the Deal with Unsplash and Imgix?

Unsplash uses the Imgix rendering API (link), a powerful image processing service that dynamically resizes, crops, and optimizes images for web delivery. Every image URL from Unsplash is processed through Imgix, which is why the URLs are often filled with parameters.

Check out the rendering API documentation to set your custom settings that will be integrated in the copied URL

Conclusion: No More Unsplash URL Drama!

If you’re a developer who frequently uses Unsplash images, "CopySplash" can save you a lot of time and effort. Give it a try, and Whether you have an idea for a new feature, want to improve the code, or help with documentation, your input is welcome!

Links:

  • CopySplash Extension
  • CopySplash Code
  • Imgix
  • Unsplash
Release Statement This article is reproduced at: https://dev.to/dalisys/how-to-use-unsplash-images-in-your-code-4me8?1 If there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3