<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ashish Arora</title>
    <description>The latest articles on DEV Community by Ashish Arora (@ashish4arora).</description>
    <link>https://dev.to/ashish4arora</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F731644%2F95ce1471-10e5-43c1-9702-fb1a0ba20fbf.png</url>
      <title>DEV Community: Ashish Arora</title>
      <link>https://dev.to/ashish4arora</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ashish4arora"/>
    <language>en</language>
    <item>
      <title>Appwrites Avatars Service</title>
      <dc:creator>Ashish Arora</dc:creator>
      <pubDate>Wed, 20 Oct 2021 18:30:29 +0000</pubDate>
      <link>https://dev.to/ashish4arora/appwrites-avatars-service-4gae</link>
      <guid>https://dev.to/ashish4arora/appwrites-avatars-service-4gae</guid>
      <description>&lt;p&gt;&lt;strong&gt;So what is Avatars Service?&lt;/strong&gt;&lt;br&gt;
Appwrite is a self-hosted solution that provides developers with a set of easy-to-use and integrate REST APIs to manage their core backend needs. One such API service provided by Appwrites is the Avatar service. The avatar service helps you to complete standard tasks related to images, icons and avatars.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Okay, that sounds like something I need to use very often, could you please explain the use cases further?&lt;/strong&gt;&lt;br&gt;
Using the avatar service you can fetch country flags, browser icons, generate QR codes, get images from URL, get payment method logos, get favicon of any remote URL and so on...&lt;/p&gt;

&lt;p&gt;Not only this, but this service also allows you to resize, crop and change the output image quality to get the best performance and visibility required in your project&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aUWfQ3cE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://media3.giphy.com/media/FlWgXEtj5aM5G/giphy.gif%3Fcid%3Decf05e477zbua8kwkmih9mohuiekm317u8633xyslqgbwzsw%26rid%3Dgiphy.gif%26ct%3Dg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aUWfQ3cE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://media3.giphy.com/media/FlWgXEtj5aM5G/giphy.gif%3Fcid%3Decf05e477zbua8kwkmih9mohuiekm317u8633xyslqgbwzsw%26rid%3Dgiphy.gif%26ct%3Dg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hmm, Sounds cool! But can you please explain me how to use it in my project?&lt;/strong&gt;&lt;br&gt;
Yeah sure I could explain it using some examples, do you want to learn using it for client based applications or using server side integrations?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Well, TEACH ME BOTH!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Okay so I’ll explain you a few examples in each scenario&lt;br&gt;
Let’s start learning using it to build client based applications and websites. The first step is to setup appwrite web sdk, you can do it by following &lt;a href="https://github.com/appwrite/sdk-for-web"&gt;https://github.com/appwrite/sdk-for-web&lt;/a&gt;&lt;br&gt;
I hope that you have read the page above. Anyways, I’ll start by initialising the sdk object using Appwrite server API endpoint and project id which can be found in your project settings page.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const sdk = new Appwrite();

sdk
    .setEndpoint('http://localhost/v1') // Your Appwrite Endpoint
    .setProject('455x34dfkj') // Your project ID;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once we are done with this. We’ll begin with our first task. The task is to get the Credit Card icon for major banking providers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Request Type:&lt;/strong&gt; &lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;GET&lt;/th&gt;
&lt;th&gt;/v1/avatars/credit-cards/{code}&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The credit card endpoint returns us the icon of the credit card provider. &lt;br&gt;
An example request can be&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let result  = sdk.avatars.getCreditCard(‘visa’);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;result will contain a resource url of a png image.&lt;/p&gt;

&lt;p&gt;We can also use &lt;code&gt;width&lt;/code&gt;, &lt;code&gt;height&lt;/code&gt; and &lt;code&gt;quality&lt;/code&gt; arguments&lt;br&gt;
The required argument &lt;code&gt;code&lt;/code&gt; is be a string with possible values: amex, argencard, cabal, censosud, diners, discover, elo, hipercard, jcb, mastercard, naranja, targeta-shopping, union-china-pay, visa, mir, maestro&lt;/p&gt;

&lt;p&gt;Whereas &lt;code&gt;width&lt;/code&gt;, &lt;code&gt;height&lt;/code&gt; and &lt;code&gt;quality&lt;/code&gt; are optional integer arguments. The arguments &lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt; can contain an integer between 0 to 2000, default being 100. However, the argument quality can contain an integer between 0 to 100, default being 100.&lt;/p&gt;
&lt;h3&gt;
  
  
  Let’s Try another task
&lt;/h3&gt;

&lt;p&gt;This time we’ll get a &lt;strong&gt;country flag&lt;/strong&gt; instead.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Request Type:&lt;/strong&gt; &lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;GET&lt;/th&gt;
&lt;th&gt;/v1/avatars/flags/{code}&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This endpoint can be used to get different country flags. The argument receives a 2 letter country code. Just like in the previous example &lt;code&gt;width&lt;/code&gt;, &lt;code&gt;height&lt;/code&gt; and &lt;code&gt;quality&lt;/code&gt; arguments can be used in this case aswell.&lt;br&gt;
The required argument code is a string which denotes the country code in &lt;strong&gt;ISO Alpha-2&lt;/strong&gt; country code format&lt;/p&gt;

&lt;p&gt;An example request can be&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let result = sdk.avatars.getFlag(‘af’);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;result contains resource URL containing image of flag in png format.&lt;/p&gt;

&lt;p&gt;This &lt;strong&gt;last task&lt;/strong&gt; we’ll be doing for the client integrated api requests will be to get QR code&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Request Type:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;GET&lt;/th&gt;
&lt;th&gt;/v1/avatars/qr&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This request converts plain text to a QR code image. &lt;br&gt;
An example request can be&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let result = sdk.avatars.getQR(‘[TEXT]’)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;result contains resource URL containing image of qr code in png&lt;br&gt;
There are a variety of optional query parameters to change the size and style of resulting image.&lt;/p&gt;

&lt;p&gt;These are &lt;code&gt;size&lt;/code&gt;, &lt;code&gt;margin&lt;/code&gt; and &lt;code&gt;download&lt;/code&gt;. &lt;code&gt;size&lt;/code&gt; and &lt;code&gt;margin&lt;/code&gt; are integer type arguments accepting integers in range 0 to 1000 and  0 to 10 respectively. The default value of size parameter is 400 whereas for margin is it 1.&lt;/p&gt;

&lt;p&gt;The parameter download accepts a Boolean type value, which returns image with &lt;code&gt;Content-Disposition: attachment&lt;/code&gt; headers for the browser to start downloading it. ‘0’ should be passed for no header and ‘1’ otherwise. Default value is set to ‘0’&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PHEW! That was a lot, please tell me about Server integrated requests&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Sure, I’ll teach through a few examples how to send requests using Server Integrated with Python SDK. To learn how to using Appwrite python SDK check this out &lt;a href="https://github.com/appwrite/sdk-for-python"&gt;https://github.com/appwrite/sdk-for-python&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope that you have read it already. Let’s start by initialising our sdk&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from appwrite.client import Client
from appwrite.services.users import Users

client = Client()

(client
  .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
  .set_project('5df5acd0d48c2') # Your project ID
  .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
  .set_self_signed() # Use only on dev mode with a self-signed SSL cert
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Initialize your SDK with Appwrite server API endpoint and project ID which can be found in the project settings page and the API secret key from project’s API keys section.&lt;br&gt;
Make sure your API key is granted with access to the &lt;code&gt;avatars.read&lt;/code&gt; permission scope&lt;br&gt;
Once this is set, we’ll begin with our next task which is to get image from URL&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Request Type:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;GET&lt;/th&gt;
&lt;th&gt;/v1/avatars/image&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This endpoint can be used to fetch a remote image URL and crop it to the needed image size. This endpoint is especially useful in cases when you need to crop and display remote image in your app.&lt;/p&gt;

&lt;p&gt;An example request can be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;avatars = Avatars(client)
result = avatars.get_image(‘https://example.com’)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;result contains the image resource url&lt;/p&gt;

&lt;p&gt;The required argument is &lt;code&gt;url&lt;/code&gt;, which contains a string i.e. the Image URL which needs to be cropped&lt;/p&gt;

&lt;p&gt;The other optional arguments which could be used are &lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt;, both integer type arguments which can be used to resize preview image width. They should contain integer between 0 to 2000&lt;/p&gt;

&lt;p&gt;The other methods available are:&lt;br&gt;
&lt;/p&gt;
&lt;li&gt; Get Favicon: &lt;code&gt;/v1/avatars/favicon&lt;/code&gt;
ExampleCode:

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;avatars = Avatars(client)

result = avatars.get_favicon('https://example.com')
&lt;/code&gt;&lt;/pre&gt;





&lt;/li&gt;
&lt;br&gt;&lt;br&gt;
&lt;li&gt;Get User Initials &lt;code&gt;/v1/avatars/initials&lt;/code&gt; Example Code:

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;avatars = Avatars(client)

result = avatars.get_initials()
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;This contains &lt;code&gt;name&lt;/code&gt;,&lt;code&gt;width&lt;/code&gt;, &lt;code&gt;height&lt;/code&gt;,&lt;code&gt;color&lt;/code&gt;,&lt;code&gt;background&lt;/code&gt; arguments which are all optional&lt;/p&gt;


&lt;/li&gt;

&lt;p&gt;These were some examples which would help you understand how to use the appwrite avatars service using both client side and service side integrations. To know more you may read the documentation at &lt;a href="https://appwrite.io/docs/client/avatars"&gt;https://appwrite.io/docs/client/avatars&lt;/a&gt;. Hope this would help you in understanding avatars service better&lt;/p&gt;

</description>
      <category>appwrite</category>
    </item>
  </channel>
</rss>
