Skip to main content

How to reduce the image size without loosing the quality using WebP Images

WebP is an image file format from Google that provides lossy compression (like JPEG) as well as transparency (like PNG) but can provide better compression than either JPEG or PNG. Lossy WebP images are supported in Android 4.0 (API level 14) and higher, and lossless and transparent WebP images are supported in Android 4.3 (API level 18) and higher. This page shows how to convert images to WebP format and how to convert WebP images to PNG format.

Convert images to WebP:

Android Studio can convert PNG, JPG, BMP, or static GIF images to WebP format. You can convert individual images or folders of images. To convert an image or folder of images, proceed as follows:
  1. Right click on an image file or a folder containing a number of images files, and then click Convert to WebP.
  2. The Converting Images to WebP dialog opens. The default settings depend on the minSdkVersion setting for the current module.


    Figure 1. The Converting Images to WebP dialog.

  3. Select either lossy or lossless encoding. Lossless encoding is only available if your minSdkVersion is set to 18 or higher. If you select lossy encoding, set the encoding quality, and choose whether or not to view a preview of each converted image before saving.
    You can also choose to skip converting any files where the encoded version would be larger than the original, or any files with transparency or an alpha channel. Because Android Studio only allows you to create transparent WebP images if your minSdkVersion is set to 18 or higher, the Skip images with transparency/alpha channel checkbox is automatically selected if your minSdkVersion is lower than 18.

    Note:
    9-patch files cannot be converted to WebP images. The converter tool always automatically skips 9-patch images.

  4. Click OK to begin the conversion. If you are converting more than one image, the conversion is a single step, and can be undone to revert all the images you converted at once.

    If you selected lossless conversion above, the conversion happens immediately. Your images are converted in place in their original location. If you selected lossy conversion, continue on to the next step.

  5. If you selected lossy conversion, and you chose to view a preview of each converted image before saving, Android Studio shows you each image during the conversion so you can inspect the conversion result. (If you did not choose to view a preview, Android Studio skips this step, and converts your images immediately.) During the preview step, you can adjust the quality setting for each image individually, as described below.


    Figure 2. Converting a JPG to WebP format at 75% quality

    Figure 2 shows the original JPG image on the left and the lossy encoded WebP image on the right. The dialog shows the file size for the original and the converted image. You can drag the slider left or right to change the quality setting and immediately see the effect on the encoded image and the file size.

    The middle area shows the pixels that differ between the original and the encoded image. In figure 2, with the quality set to 75%, there's almost no difference between the two images. Figure 3 shows the same image encoded with the quality set to 0%.


    Figure 3. Converting a JPG to WebP format at 0% quality

    Note: If you set the quality to 100% and the minSdkVersion is set to 18 or higher, Android Studio automatically switches to lossless encoding instead.

    Select a quality setting for each image you review. If you are converting more than one image, click Next to advance to the next image.

  6. Click Finish. Your images are converted in place in their original location.

Convert WebP images to PNG:

If you want to use a WebP image from your project for another purpose (for example, in a web page that needs to correctly display images in a browser without WebP support), you can use Android Studio to convert WebP images to PNG format. To convert a WebP image to PNG, proceed as follows:
  1. Right click on a WebP image in the Android Studio, then click Convert to PNG.
  2. A dialog appears, asking if you would like to convert the image to PNG, deleting the original WebP file, or keep the original WebP file as well as the new PNG file. Click Yes to delete the original WebP file, or No to retain the WebP file in addition to the PNG file. Your image is converted immediately.


Comments

Popular posts from this blog

Vertical AutoScrolling TextView in Android

In android by default we can scroll the text in horizontal using marquee in layout, but if we want to scroll the text in vertical its not possible by default. So here we will learn to create a custom TextView which will auto-scroll in vertical direction. Source Code:  VerticalScrollingTextView-Android Create a AutoScrollingTextView.class which extends TextView: @SuppressLint ( "AppCompatCustomView" ) public class AutoScrollingTextView extends TextView { private static final float DEFAULT_SPEED = 65.0f ; public Scroller scroller ; public float speed = DEFAULT_SPEED ; public boolean continuousScrolling = true; public AutoScrollingTextView (Context context) { super (context) ; init( null, 0 ) ; scrollerInstance(context) ; } public AutoScrollingTextView (Context context , AttributeSet attrs) { super (context , attrs) ; init(attrs , 0 ) ; scr

Flexbox inside the RecyclerView as a LayoutManager (FlexboxLayoutManager).

Currently google has release the Flexbox which can be used for building flexible layouts using FlexboxLayout, it can be interpreted as an advanced LinearLayout because both layouts align their child views sequentially. For more detail on this flexbox-layout But here we are gonna work on Flexbox with RecyclerView. Flexbox with a large number of items in a scrollable container! Let's first see what are the Supported attributes / features comparison Due to some characteristics of the RecyclerView, some Flexbox attributes are not available/not implemented to the FlexboxLayoutManager. Here is a quick overview of the attributes/features comparison between the two containers. Attribute / Feature FlexboxLayout                FlexboxLayoutManager (RecyclerView) flexDirection flexWrap (except wrap_reverse ) justifyContent alignItems alignContent - layout_order - layout_flexGrow layout_flexShrink layout_alignSelf layout_fl

Android RecyclerView and StaggeredGridLayoutManager with Picasso/Glide

This project is there in GitHub https://github.com/yuvaraj119/Picasso-RecyclerView-StaggeredGridLayoutManager You can download and start customizing it for your project also. How to use with Picasso Picasso + RecyclerView + StaggeredGridLayoutManager Its the enhanced version of this project https://github.com/pohh/slotmachinepicasso were there was a problem with Picasso + RecyclerView + StaggeredGridLayoutManager shuffles resizable recycler views infinitely issue posted on github https://github.com/square/picasso/issues/918 I have made some changes now it works with Picasso and Glide without any shuffles and position change Currently this project is done with Picasso If you want to use it with Glide How to use with Glide Glide + RecyclerView + StaggeredGridLayoutManager Add dependencies for Glide https://github.com/bumptech/glide Remove Picasso library from dependency and remove all the codes of Picasso from MyGridAdapter.java and also from other p