Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 8733

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 60k
Author
Asked: November 28, 20242024-11-28T03:53:09+00:00 2024-11-28T03:53:09+00:00

#30DaysOfAppwrite : Appwrite Avatars API

  • 60k

Intro

#30DaysOfAppwrite is a month-long event focused on giving developers a walk-through of all of Appwrite's features, starting from the basics to more advanced features like Cloud Functions! Alongside we will also be building a fully-featured Medium clone to demonstrate how these
concepts can be applied when building a real-world app. We also have some exciting prizes for developers who follow along with us!

Appwrite Avatars API

Welcome to Day 21 👋 . Today we're going to take a look at Appwrite's Avatars API and check out some neat features it has under the hood!
The Avatars API primarily allows you to generate icons and avatars for a variety of use cases. Let's take an in-depth look into what it has to offer.

Credit Card Icons

You can easily get credit card icons for the most popular Credit Card companies like AmEx, Discover, JCB, Mastercard, Visa, Maestro, etc. The Get Credit Card Icon endpoint also allows you to customize the icon size and quality while requesting for it. You can find the complete list of supported credit cards here.

Browser icons

The Get Browser Icon endpoint allows you to get icons of some commonly used browsers conveniently. If you haven't seen it already, we use this endpoint in the Appwrite console to display information about a user's session.

Browser Icons Example

You can find the complete list of supported browser icons here.

Country flags

Similar to the browser icons endpoint, the Get Country Flag endpoint allows you to get icons for country flags. You can see it in use in the Appwrite console screenshot above. You can find the complete list of all the country codes and flags here.

Images from a URL

The Get Image from URL endpoint is very useful if you need to crop and display remote images in your app or in case you want to make sure a 3rd party image is properly served using a TLS protocol.

Get Favicon

A favicon is a small icon or collection of icons associated with a website, web page, or web application. It's displayed within the browser tabs and bookmarks bar. The Get Favicon endpoint allows you to fetch the favicon of any remote URL.

Favicon Example

QR Code

The Get QR Code endpoint allows you to generate QR codes for any string. How you use this is only limited by your creativity, as you can use this to share URLs, phone numbers, and even base64 encoded images. We will use this functionality to add a social sharing feature to our demo app.

Get User Initials

The Get User Initials endpoint provides a convenient way to get avatars for your users based on their initials. You can use this as a placeholder until the user uploads a profile image. You can also use this endpoint to generate avatars for any string (not necessarily a name). Additionally, you can tweak the image size, text color, and background color if you aren't happy with the defaults.

Let's write some Code

In our demo app, we will add a share article feature. This feature will allow the user to share the article to various social media platforms and even generate a QR code for the current URL, which can be shared with your friends.

The first step is to add a new function in src/appwrite.js to make a call to the Avatars service:

  export const api = {     ...     getQRcode: text => sdk.avatars.getQR(text)     ... }   
Enter fullscreen mode Exit fullscreen mode

The network layer is now ready. Let's head to the src/routes/Post.svelte component, where we will create the buttons for sharing. Copy the following markup into the last section of the HTML:

  <!-- Share --> <section>   <div class="share-buttons-container">     <div class="share-list">       <!-- FACEBOOK -->       <a class="fb-h" on:click="{fbs_click}" target="_blank">         <img           src="https://img.icons8.com/material-rounded/96/000000/facebook-f.png"         />       </a>        <!-- TWITTER -->       <a class="tw-h" on:click="{tbs_click}" target="_blank">         <img           src="https://img.icons8.com/material-rounded/96/000000/twitter-squared.png"         />       </a>        <!-- LINKEDIN -->       <a class="li-h" on:click="{lbs_click}" target="_blank">         <img           src="https://img.icons8.com/material-rounded/96/000000/linkedin.png"         />       </a>        <!-- REDDIT -->       <a class="re-h" on:click="{rbs_click}" target="_blank">         <img src="https://img.icons8.com/ios-glyphs/90/000000/reddit.png" />       </a>        <!-- PINTEREST -->       <a         data-pin-do="buttonPin"         data-pin-config="none"         class="pi-h"         on:click="{pbs_click}"         target="_blank"       >         <img src="https://img.icons8.com/ios-glyphs/90/000000/pinterest.png" />       </a>        <!-- QR Code -->       <a class="pi-h" on:click="{qrcode_click}" target="_blank">         <img           src="https://img.icons8.com/ios-glyphs/60/000000/qr-code--v1.png"         />       </a>     </div>   </div>   {#if qrCode}   <img src="{qrCode}" alt="No QR Code" />   {/if} </section>   
Enter fullscreen mode Exit fullscreen mode

We need to add some styling to this as well. I'd recommend copying all the styling from here.

Now it's time to add some Javascript to stitch it all together. In the <script> section of src/routes/Post.svelte add the following code:

  let qrCode = null; var pageLink = window.location.href; var pageTitle = String(document.title).replace(/&/g, "%26"); const fbs_click = () => {   window.open(     `http://www.facebook.com/sharer.php?u=${pageLink}&quote=${pageTitle}`,     "sharer",     "toolbar=0,status=0,width=626,height=436"   );   return false; }; const tbs_click = () => {   window.open(     `https://twitter.com/intent/tweet?text=${pageTitle}&url=${pageLink}`,     "sharer",     "toolbar=0,status=0,width=626,height=436"   );   return false; }; const lbs_click = () => {   window.open(     `https://www.linkedin.com/sharing/share-offsite/?url=${pageLink}`,     "sharer",     "toolbar=0,status=0,width=626,height=436"   );   return false; }; const rbs_click = () => {   window.open(     `https://www.reddit.com/submit?url=${pageLink}`,     "sharer",     "toolbar=0,status=0,width=626,height=436"   );   return false; }; const pbs_click = () => {   window.open(     `https://www.pinterest.com/pin/create/button/?&text=${pageTitle}&url=${pageLink}&description=${pageTitle}`,     "sharer",     "toolbar=0,status=0,width=626,height=436"   );   return false; }; let qrcode_click = async () => {   qrCode = await api.getQRcode(pageLink); };   
Enter fullscreen mode Exit fullscreen mode

That's it. Really! You can now share your article to social media platforms with one click and share a QR code with a link to the article. If you want to see the exact file changes in this feature, you can look at this PR.

Credits

We hope you liked this write-up. You can follow #30DaysOfAppwrite on Social Media to keep up with all of our posts. The complete event timeline can be found here

  • Discord Server
  • Appwrite Homepage
  • Appwrite's Github

Feel free to reach out to us on Discord if you would like to learn more about Appwrite, Aliens or Unicorns 🦄. Stay tuned for tomorrow's article! Until then 👋

30daysofappwriteflutterjavascriptwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 1k
  • Popular
  • Answers
  • Author

    How to ensure that all the routes on my Symfony ...

    • 0 Answers
  • Author

    Insights into Forms in Flask

    • 0 Answers
  • Author

    Kick Start Your Next Project With Holo Theme

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.