How To Compress Png Image Using Java

Each image has a size of 100 Kiloybte. Creates highly optimized APNG files, uses lots of tricks to make them as small as possible. JPEG is a joint standard of the International Telecommunications Union (ITU-T T. Photoshop has a Lab color mode, which helps us better prepare the image for compression using the JPEG optimizer. This will provide massive size reduction on images. - current time, default format hhmmss. To read and write ICO files in Java, we use the image4j image library. How to Compress PNG Images in Windows Amit kumar January 12, 2015 Image compression has become necessary thing of every user because everyone want fast upload, quick share , and very small size attachments of images while using online. Here you go:. These guides (one for Windows, one for OS X) will show you how to compress. For example, if the input file uses 256 or fewer distinct colors, PNGOUT will choose the palette color type (/c3) to compress the image. Once an image is loaded off the disk and is formatted for rendering, it will use the same amount of memory regardless of whether that image was saved to disk using PNG, JPEG, or GIF. The file's format is determined by this function, as can be seen in the filename (JPEG, PNG, and some others are supported). When choosing the PNG-8 image format, you may see a decrease in the number of colors in the image. jpg' -exec cwebp -q 70 {} -o {}. Batch Picture Resizer is the best image compression software that allows you to resize your photos and shrink it down to KB size without losing the visual quality of the photos. We loop through every pixel of this image, using the or operation to override its least significant bit. Our Photo Size compressor Tool can compress both. In the example below, we've saved our image as a PNG. If you're willing to sacrifice compression speed in exchange for ridiculously good compression ratios, you'll want to try using the optional zopfli compressor. Here you go:. So, even if the jpg compressed image itself is new set of data, and has it's own structure, you will get a bigger file in general after the second compression, or at least not smaller. Graphics2D class to resize image in java. Although PNG‑8 compression is lossless, optimizing an original 24‑bit image as an 8‑bit PNG file can subtract colors from the image. Export HTML table to Excel / CSV / PDF / JSON / PNG using jQuery Posted on 15-01-2019 by Karthikeyan k This plugin is very easy to implement it in your projects who wants to export the html table data instantly. The easiest way to use them is to select the text you want in the CODE section, and then click the "CODE" button. ’ in their name. In this page, we will discuss handling of Images with PDF. The SaveTemporary function is used to temporarily save the image into the provided MemoryStream during each iteration. We show how to create a script to compress many PNG files with the TinyPNG plugin for Photoshop. png Extension - List of programs that can open. Defining the graph to read and batch images from. The image4j library allows you to read and write certain image formats in 100% pure Java. The script produces a lossless optimization for the images. We previously used ImageIO to read PNG files, but over time became increasingly dissatisfied as we discovered more and more issues. The SVG looks great at any size, whereas the PNG next to it starts to look blurry at larger display sizes. so how can I compress image by passing bytes or percentage as a parameter or using anyother calculations in java (by using API or image-processing Tool) so,that I can get compressed version of image as suggested by google. You can get it here. EncoderValue provided by GDI+ contains most of the compression encoder information that applies to an image. Right-click on the package then select "New" -> "Java class". This post explains how to do the gif, jpg, bmp, png image compression using JAI APIs. This works for me, the problem is that I am trying to convert the D3 graph to PNG inorder to create a PDF file using PhantomJS. Select the file format using the Format dropdown. I will be using Apache Commons Codec library to achieve the ‘Convert Image to String and String to Image in Java’. Hello people I need your help for program related to ImageIO API while working on PNG images. The fewer bytes per image, the faster the browser can download and render the content on your users' screens. (98KB) Using in Java. Description: This plugin saves in PNG format using the ImageIO classes available in Java 1. Below you'll find basic tutorials to help you get started and advanced tutorials to sharpen your skills. There are plenty of GUI applications or web applications which are available that will help you to optimize the images. I use the GIMP photo editor which automatically saves the converted files in. Each algorithm focuses on a different aspect. However, issuing the command "File f = new File("blob. VeryPDF Free PDF Compress Online can compress and reduce storage size of your PDF files online for free. Convert image to PNG. Example Java code to write PNG images in Java: Here are some code examples using Image IO, JAI and JDeli to save a BufferedImage to a PNG format – Using Image IO Javadoc and included in JDK. The actual compression takes place in just oneline, that is the imagejpeg function. In order to compress an image, we read the image and convert into BufferedImage object. After Scanning documents, you will get documents in Image file formats like. We previously used ImageIO to write TIFF files, but over time became increasingly dissatisfied as we discovered more and more issues. PNG (Portable Network Graphics) files are usually used to share media without losing fidelity and picture quality, at the expense of a larger file size than images that undergo lossy compression. This is the default value for all PNG transformations. Java's ImageIO package (built in) does not support Tiff file decoding. Resolution (dpi) is not really an attribute of an image. The below method will encode the Image to Base64 String. How to use this tool? First of all - you must specify png file that will be used by online png resize tool, the second obligatory step - choose width and height of furute image, it can be size in pixels or in percents (use dropdown menu for change), limit of future filesize is 20MegaPixels. Basically, you have a few solutions to reduce the size of an image but most of the time it will decrease the quality too. Send image and videos from your device directly to Camtasia or Snagit. Using tools like these always create equivalent PNG images. PNG is an open source file format that supports tight lossless compression. We write the file in multiple formats. png" How to use JavaScript. SuperPNG is a free, open source Adobe Photoshop plug-in for using PNG ("ping") files. We show how to create a script to compress many PNG files with the TinyPNG plugin for Photoshop. PNG files are used for storing bit-mapped images using lossless data compression. FileOptimizer is an excellent image compression tool. libspng: An alternative to libpng with a simple C API. First, the bugfixes - PNGGauntlet will now correctly add directories that have a ‘. Compress vector graphics compresses the vector content streams in the PDF. Tile size: Compression (Optional) This defines the type of data compression that will be used to store the raster dataset. For this reason, instead of using the jQuery. Here the one that I would like to share with you. I tried with an already compressed image using a desktop application, Kraken compress that file to an extra 10% without losing on quality. Users with modern browsers will see a highly detailed image, while users with older browsers (such as IE 6) or with JavaScript disabled will still be able to see the image but with less detail. Using Cram. Upload your file. How to Write an Image in Java. The game will expect you to use a specific naming format for the cards. The Problem During your development of robust, rich-client web applications, you’ll quickly develop a set of controls that use JavaScript to provide your application’s. There’s a lot to image optimisation, if you are interested The Book of Speed’s chapter on Optimizing Images is very good. Yes, click on the UPLOAD & COMPRESS FILE(S) tab and choose the CSS file you want to compress. Teaching you how to produce web pages that everyone can use. The script demo_decompress. Image comparison in java using RGB value How to compare (RGB value) two images using java This example helps you to compare two images (either jpeg or png) using pixel. png' file extension. So, if the speed of your site is paramount and you want the best balance between optimization and picture quality, we recommend you to continue to use Lossy optimization. 3 OR gradle dependency as below: dependencies {. You can do this on both Windows and Mac computers. NET worker process. io is a powerful online tool for reducing drastically the size of your images and photos whilst maintaining a high quality with almost no difference before and after compression. To show the images as large as possible on Facebook, make the long size of your image 2048px. Even though their website had already been designed using a mix of JPGs and PNGs and were stored in a number of places around the web, ImageKit took care of automating the image formats right from the original URLs. if i get other than ty. How to Make a Slideshow with a Transparent PNG Frame. Just like PNGGauntlet for Windows, ImageOptim compresses PNG images without any loss of quality. Convert your JPG files to PNG image. Paste it into your HTML or CSS. Thanks keep posting more blogs. Below are two versions of the same image: a PNG image on the left and an SVG on the right. Therefore, it has no quality parameter (quality is always 100 %). and applying various PNG optimization techniques like stripping alpha channel if the image is not transparent, reducing the bit depths, converting true color images to indexed images if there are less than 256 colors, etc. Free image optimization tool to reduce image file size online, compress PNG, JPG, JPEG images. With this setting, WinZip will use MP3 compression and/or Jpeg compression with files of those types and the result will be a Zipx file. So here you go: * Read the files using the HTML5 FileReader API with. This is how you can compress images in your Android without losing quality. png extension. You may also like to read Convert PDF to Image using Java. if i get other than ty. The extension of this file is png. In this use case I want to compress down all images that are over 500 KB down to 80% quality which brings the images down to about 100KB. gnuplot ), and importing paths (e. Note: It is important to note that any figures containing WebGL traces (i. You can use for bulk image compression. It contains platform-agnostic java classes. See the discussion below about the 'enabled' config attribute for how to disable it for development. the width and height attributes in HTML cannot accept javascript as parameters to do what you are trying to do, you'd have to write out your image WITH the javascript (document. The results are shown at the top. JDeli is a high speed Java Image Library that includes everything you need to read, write, process or convert a large number of image file types in Java. Let's see how you can use PNGQuant to compress your PNG images for the web in this short tutorial. Java Tutorials - JPEG image compression Video tutorial on how to compress JPEG images using java. An example programme that uses libPNG is linked to below. If these images get downloaded 10,000 times per month, you'd save 250,000 Kilobyte, or 250 Megabyte of traffic. JPG--Which Is Best? One of the most important and difficult concepts to learn about digital imaging is which format is best for displaying graphics and photos on the web. For example, if the input file uses 256 or fewer distinct colors, PNGOUT will choose the palette color type (/c3) to compress the image. jar [options] Here, the first argument must be a command. Using JPEG implies breaking an image into tiles of 8x8 pixels, where each tile gets compressed. iText provides Image class using which we can add image in PDF. You can use Fiddler to see whether your server accepts request bodies with Content-Encoding; click Rules > Customize Rules. png image files. If done properly, JavaScript buttons give very impressive look and feel. Canvas is just a container for your graphics, JavaScript is used to draw. Feel free to give your suggestions and recommendations about image compression tools. Most images that you download online are already compressed. The only class contained PDPageContentStream was moved to the. Among the three methods to compress PNG photos, FonePaw Online Photo Compressor is most convenient and can really reduce the image size to 70% or 80%, while Paint and Photoshop actually shrink the images by resizing. The Image I/O class provides a simple way to save images in a variety of image formats in the following example:. This list is created by collecting extension information reported by users through the 'send report' option of FileTypesMan utility. Re: Convert PDF files to PNG Images using Azure Functions @Raj Finn - Just a guess, perhaps your storage container name and sub folder and file name do not match? Upper and lower case does matter ("UsConstitution" is not the same as "USCONSTITUTION"). Image Functions Using the GD Library; How to Add Text to An Image; In order to add text to an image, you need two things: the image and the font. Alternatively, you can choose to have your images written to separate files in a predefined directory, in one of the two raster formats required by the SVG specification: JPEG or PNG. We will automatically detect the type of image and optimise with the TinyPNG or TinyJPG engine accordingly. jpegoptim is a simple utility to optimize JPEG images without. Take a trial of them and we are sure that you will love to use them. In the following example, we convert a PNG image into an ICO image. But, older versions of IE are always seen around that may mess with sending using FormData. The type of image dictates which image format is best to use. The Tinify API allows you to compress and optimize JPEG and PNG images. Furthermore, could you please show me how to change CR2 file format to JPEG. GIF is great for clipart and drawings where limited colors are in use. With this feature, you can compress/decompress data on the fly in your Java programs. Java Graphics How to - Reduce the size of an image file. getDefaultWriteParam(). Today, I will show you step by step how to convert PSD to HTML based on a simple Web 2. To decrease the size of data that's being transferred between your server and your visitors, you can enable the gZIP compression for your images, CSS and JavaScript files. So you can rest easy: using TIFF compression will not degrade your image quality. Tiny PNG is the best image optimizer online tool and it will support compression of both. Go up to the Picture Tools Format tab Click on the Compress Pictures command Select your Compression options (see image below) Select your Resolution (see image below). When I set the compression type to BI_JPEG and write the image, I am getting an exception when reading back the image using BMP Image reader. This is only for one image but I am sure I will have lots of images for compression. 0 Environment. In the age of the Internet, there is huge competition among open source PDF editors. PDF Compressor allows you to compress PDF files, reduce pdf file size easily and quickly. Add an uploaded PNG image named cloudinary_icon as an overlay. PNG was created to both improve upon and replace the GIF format with an image file format that does not require a patent license to use. The image-processing library we use for this is the ImageMagick Library. A small size saving for each image, but it speeds up the load time of web pages and reduces the bandwidth cost for a website. Compression and Decompression in Java. The only class contained PDPageContentStream was moved to the. If you want to compare two images and find out what the differences are between them, it can be quite difficult to do it by eye alone as any differences may be subtle and hard to spot. It is best to keep your images as small as possible. Other Helper Functions. jpegtran and OptiPNG are great tools for performing lossless compression of JPEG and PNG images. Thanks in advance. image package provides an easy way to transcode an SVG document to a raster image such as JPEG, PNG or TIFF. PNGStore - Embedding compressed CSS & JavaScript in PNGs. Text to Image Converter. This of course can take some time on each image. J I C is a Javascript Image Compressor using HTML5 Canvas & File API that allows you to compress your jpeg & png images before uploading to the server (100% client-side and no extra libraries required!) - brunobar79/J-I-C. Over the time, I’ve realized one problem many of our clients meet, that is, they don’t know how to optimize images for their sites. jpg), combining images, including height and width in your markup for images and why it matters, and much more. In this folder were all my java files and this png file. Or, if you just want the overall image distortion, use this command:-> magick compare -metric PSNR rose. Yes, it is possible, the answer is “Compression at the client side using JavaScript”. Open the photo you want to compress in the GIMP program. Lossy compression means that after the image is compressed in JPEG format, it loses certain actual contents of the image; Quality of Image is reduced after JPEG compression owing to the loss of actual content of the image. But, you probably would like also to create an new image as a pixel data buffer. Step 1: Let’s create our HTML structure. About the PNG‑8 format. Base64 is a common format used for the web and email. The example Google Doodle above was exported in Photoshop’s “save for web” feature, and the image format was set to PNG8, which. The SaveTemporary function is used to temporarily save the image into the provided MemoryStream during each iteration. png compression is negligible or no compression at all here is a sample how the image is loaded and saved Or someone suggest me better. It supports responsive mobile first design by default, and it is smaller and faster than similar CSS frameworks. Take advantage of the HTML5 Canvas that is used to draw graphics on a web page. How this affects the image is controlled by these two key aspects: the type of image and the amount of compression. A buffered image is a type of image whose pixels can be modified. I had the same issue and had to not only uncheck 'compress PNG files' option in Project -> Target -> Build Settings -> Packaging, but also uncheck 'Strip PNG text', so that the png conversion tool is not called at all. We have previously discussed how to convert documents to PDF using the built-in Print to PDF feature. Directly creating a Java 2D image and rendering to it. You are asked to enter the file name and location for the PDF file, but you do not get a chance to choose a page range, the image compression, or other options. The preferred method for reading an image file of any format into a RenderedImage is: String filename = “// path and name of the file to be read,. There’s no need to use complex graphics software if you have the Movavi Converter!. Replace PNG Transparent Background Color. Simply storing the images would take up a lot of space, so there are codecs, such as JPEG and PNG that aim to reduce the size of the original image. Dynamically set width and height of image using javascript. Today’s tutorial is headed back to the basics. Add "Html to image" or "html to jpg" feature to your application now! HTML Snapshot ActiveX can download and parse web sites and save a screenshot of the page in GIF, JPG, JPEG, BMP, PNG, TIFF, WMF and EMF. 5 In the Colors box, select the number of colors, as shown in Figure 8-5. That is come across like this way. Teaching you how to create web pages. The easiest way to minify your HTML, CSS and JavaScript in WordPress is to use a plugin. Give it a try now!. Generic; using System. We mention what you can do with the ASHX file involving images. Similarly, ImageResize. There’s no need to use complex graphics software if you have the Movavi Converter!. Here the one that I would like to share with you. Runs of multiple cells on the same row with the same colour are merged into one cell using the COLSPAN. ), the script first has to decompress that file export it to RGB pixel data. If you want to change the default. A file with the TIF or TIFF file extension is a tagged image file. Nano uses lossless techniques to compress inefficient SVG codes by removing unnecessary data, resulting in the same image, but large differences in file size! * On average, more than 80% reduction in size, when gzipped. Now, i want to make the uploaded photo transparent by code if th. One of the most popular plugins for WordPress is the EWWW Image Optimizer plugin. Basically, you have a few solutions to reduce the size of an image but most of the time it will decrease the quality too. ) When transparency is in use in the type = "Xlib" variant a very light grey is used as the background and so appears as transparent if used in the plot. (example tiling, separated planar, jpeg […]. How to use. GIF is a good choice for storing line. If your image size is big, we recommend you to use this mode. We keep the ICC profile of your initial image so the colors are maintained and preserved. Skip navigation How to compress images (jpg & png) on a Mac using Automator & TinyPNG. Please expect some quality loss when convert image file from PNG to JPEG, because both are different format, some effects in PNG may not exist in JPEG image file. grunticon takes a folder of SVG/PNG files (typically, icons that you've drawn in an application like Adobe Illustrator), and outputs them to CSS in 3 formats: svg data urls, png data urls, and a third fallback CSS file with references to regular png images, which are also automatically generated and placed in a folder. How this affects the image is controlled by these two key aspects: the type of image and the amount of compression. THE DEFAULT JAVA MACHINE INSTALLED we tend to have, does not support PNG compression. PNG (Portable Network Graphics) was developed around 1995, became a W3C recommendation in 1996, and has been widely implemented in most Web browsers as soon as 1998. The level of compression depends on the user (it's that slider when you save an image) but typically JPEG allows for 10:1 file size gain with an acceptable loss in quality. Using the examples above, the jack of clubs should be called 'mainsetclubs11. I will show you how to do this using ImageIO, and secondly using JDeli. Uses a built in version of the AVI reader plugin to open an AVI file (JPEG or PNG compressed, or uncompressed) as a stack or virtual stack (one slice per video frame). Like any adaptive/dynamic compression method, the idea is to (1) start with an initial model, (2) read data piece by piece, (3) and update the model and encode the data as you go along. How do you draw an image on HTML5 canvas? Use HTML5 canvas' drawImage method in JavaScript: The drawImage method can be invoked with three different set of arguments: context. To read and write ICO files in Java, we use the image4j image library. PNG Decoder: 3. In this chapter we are going to see how you can download an image from internet, perform some image processing techniques on the image, and then again upload the processed image to a server. The java port is based heavily on this. It's very advisable to optimize images used in web, as it can save bandwidth and make websites load a little faster. So I put your picture into photoshop, and there it was - a white background. Later you decide to compress the images to save your storage space, so you implement an image compression feature in the back-end. Click now on Compress Now. For the lossy formats you can specify up to three quality levels, indicated by specific situations: When the user indicates a preference for reduced data usage. You can convert an image into JPG format using an image editing app on your computer or one of the many file conversion sites available on the web. Long load times will cause more of your customers to abandon your page in search of another one. Reference to using the command line in linux to compress and optimize all of your png, tiff, bmp, and gif image files I needed a lossless compression tool, one that I can run in the command line and easily optimize all images in an entire directory. So what are my options? These options relate to using images outside of using SiteContent especially if you are not a Premium member then you might need to either upgrade. A few days back, I talked about the best image compression WordPress plugins where I highlighted some great solutions for compressing images on your blog. It supports JPEG, PNG, GIF & SVG and files size limit is 10 MB. PNG generally produces better-looking images with smaller file sizes than GIF for the same kinds of limited-color images. Optimize your image files and photos, reduce file size of images online. To optimize PNG images or JPG images you can use the PNG Compressor or the JPEG Compressor, sometimes it can reduce the size by 50% or more. The original, uncompressed image (left) is 8. In this tutorial, I will cover the following topics: How to compress images without losing image quality. 000 companies and developers around the world who are using the API. This example demonstrates how to convert PNG to JPG image file using Java. Below is the program that searches all the files in a directory and resizes them to the given size and saves it to a different directory. PNG images are in many ways better than. Edit an image here fast and easy online. It often squeezes out 10-100 bytes off an already compressed image. There are several free tools for this which I use for my websites. Installation. CSS is a modern CSS framework with built-in responsiveness. The java port is based heavily on this. Reply Ann Weaver says:. NET, and Bool. A DOMString indicating the image format. Now, the problem is- to give Image tool the url of a byte array. For instance a 2. The downside of the PNG compression technique is that you cannot shrink the file size as much as with JPEG. png")" makes Java look into the folder "src" and NOT in the folder "spiro2"! So, by altering the code to this:. Compressed Image File Formats is an appealingly compact and useful guide to some of today's most popular file formats used for image data. APNG Assembler is an easy-to-use tool to make Animated PNG from PNG/TGA image sequence. You can use your own background image and font. Compressing images. Below you'll find basic tutorials to help you get started and advanced tutorials to sharpen your skills. Dears, I am developing a page to upload users signatures with rules that: *Image must be PNG. png images correctly in Unity? Hello, I'm creating my first Unity game for Android and I ran in some problems about using and importing png images correctly. Nano uses lossless techniques to compress inefficient SVG codes by removing unnecessary data, resulting in the same image, but large differences in file size! * On average, more than 80% reduction in size, when gzipped. Loading an external GIF, PNG JPEG image format file into the internal image representation used by Java 2D. You can load image from file using the codes as follows. This compression is why you might want a PNG to JPG converter as it will let you free up hard disk space. Set the resolution to 72 pixels/inch. Answer: Use the JavaScript width and height property. Apart from PNG's, the software can also compress GIF and JPEG image formats. Even though their website had already been designed using a mix of JPGs and PNGs and were stored in a number of places around the web, ImageKit took care of automating the image formats right from the original URLs. I’ve been on a web tweaking kick lately: how to speed up your javascript, gzip files with your server, and know how to set up caching. The basic approach is: Do an XMLHttpRequest for a file, and set the responseType to “arraybuffer”. The picture frame image is a 24-bit PNG which includes a drop shadow. I used to take one of my favorite tools Photoshop CC 19. Animation speed is retrieved from image frame rate. Now, the problem is- to give Image tool the url of a byte array. Once again, you use the SVGGeneratorContext for. You can compress photos on both Windows and Mac computers by using a free website, or you can use your computer's Photos app to compress an image to a smaller size. Nykaa was able to capitalize on this image optimization strategy from ImageKit. Stack Exchange Network. PNG compression in ImageMagick can be configured with three settings, -define png:compression-filter, -define png:compression-level and -define png:compression-strategy. In this post, let’s find out how to compress and resize/scale images in ASP. In this article I will show you how to read JPEG images in Java using ImageIO, JAI and JDeli. Give it a try now!. In the following example, we convert a PNG image into an ICO image. The latest code adds the ability to optimize png images using the new zopfli deflate compression algorithm. Thanks for A-2-A. png-lossy-[q] q in [0. In free evaluation version of Java Barcode library, you will find compiled Java barcode library (single Jar file) to create, print Code 128 and other linear, 2d barcodes in your Java projects, detailed tutorial for generation barcodes in Java, and complete sample Java source code to generate Code 128 in Java class. to read dicom file. A normal image file takes about two bytes to encode each pixel. 31 If the reconstructed image is a subimage of the image, the compare program returns the best match offset. Now, we have an actual PNG image with base64 encoded image data in the source. Click here to select an image from your device, press Ctrl+V to use an image from your clipboard, drag and drop a file from desktop, or load an image from any example below. You may have to double-click the picture to select it and open the Format tab. This is very helpful when sending Image files or other binary files to Web server using Http post. There’s a lot to image optimisation, if you are interested The Book of Speed’s chapter on Optimizing Images is very good. Click UPLOAD FILES to choose up to 20 PNG images you want to compress. createGraphics(). PNGout was not exactly fast to begin with, so imagining something that's 80 times slower (at best!) to compress an image or a file is definite cause for concern. This allows you to strip out any unwanted space-gobbling objects, remove tags, and compress any pesky images further. By using this function we can make images small-sized without losing image quality. PSD file, the compressed version will most likely be 5% - 50% of the original file size. We'll use the following image (img1. 0 requires at least Java 6. Using PNG instead of a high-quality JPEG for such images would result in a large increase in filesize with negligible gain in quality. Note: This option only available for image/jpeg and image/webp images. Edit an image here fast and easy online. We write the file in multiple formats. We use the latest image compression methods and intelligent algorithms to lower your image file size. In the example below, png files expire their cache 2592000 seconds after they are accessed by a browser. Users hate waiting, we get frustrated by buffering videos and. Many fans use this format when it comes to compressing images to make the web run fast. Step 5:Click "Convert Now" to finish the process. Encode Image to Base64 String. Use FileReader to read that file and load it into the page and/or localStorage. Optimus allows images to be optimized and then stored. JPG uses lossy compression and high compression ratios that make the size of image files significantly smaller while preserving good picture quality. GIF creates a table of up to 256 colors from a pool of 16 million. The following matlab project contains the source code and matlab examples used for image compression. You have to go through bunch of codes to compress an image as per preferred size.