![]() useful to create thumbnails) public resizeExactCrop(files: File, toWidth: number, toHeight: number): Observable startX and startY tell where the cropping should start as coordinates. If you want only one limit just set the other max to a very high value: for example resize(,2000,10000).subscribe( Crop image crop(files: File, toWidth: number, toHeight: number, startX: number = 0, startY: number = 0): ObservableĬrops the given files down to the given width and height. Method to resize files if necessary down to a certain maximal width or maximal height in px. Maximal width / height resize(files: File, maxWidth: number, maxHeight: number, logExecutionTime: Boolean = false): Observable Returns an observable that for every file given, onNext receives either a File when everything went as planned or an error Object if something went wrong. Set ignoreAlpha to true if you want to ignore the alpha channel for png images and compress them nonetheless (not recommended - the alpha channel will be lost and the resulting image might differ from the original image). This reduces the quality of an image down until it fits a certain fileSize which is given as maxSizeInMB. The compressedFile is a compression as close as it can get.Ĭompress(files: File, maxSizeInMB: number, ignoreAlpha: boolean = false, logExecutionTime: boolean = false): Observable UNABLE_TO_COMPRESS_ENOUGH: Could not compress image enough to fit the maximal file size limit. The compressedFile is the result of step 15 of the compression.įILE_BIGGER_THAN_INITIAL_FILE: This should actually never happen, just a precaution. This should rarely to never at all happen. MAX_STEPS_EXCEEDED: Could not find the correct compression quality in 15 steps - abort. ![]() No compression possible unless ignoreAlpha is set to true. PNG_WITH_ALPHA: File provided is a png image which uses the alpha channel. INVALID_EXTENSION: File provided is neither of type jpg nor of type png). If an error happens, you will receive an object with the following properties:ĬompressedFile: File, reason: string and error: string When using the compression methods you should make sure to catch the error cases. Maximal filesize IMPORTANT: Catch error cases Please see the example above in Usage to see how to check if the returned value is a File.Īll the methods furthermore have a method for a single file as input aswell, which are named e.g. Import MethodsĪll the methods return an Observable, which onNext either gets a file if everything went as planned or an error object if something went wrong.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |