{"id":25352656,"url":"https://github.com/mutkuensert/bitmapcompression","last_synced_at":"2025-10-29T21:31:16.482Z","repository":{"id":226652634,"uuid":"769289734","full_name":"mutkuensert/BitmapCompression","owner":"mutkuensert","description":"A Bitmap compression utility library.","archived":false,"fork":false,"pushed_at":"2024-03-12T07:05:59.000Z","size":113,"stargazers_count":7,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-03-12T20:23:17.313Z","etag":null,"topics":["android","android-image-compressor","android-library","bitmap","image-compression"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mutkuensert.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-03-08T18:30:22.000Z","updated_at":"2024-03-12T20:23:17.314Z","dependencies_parsed_at":"2024-03-08T20:22:52.820Z","dependency_job_id":"98777ddc-14f8-4103-9675-6e04f2c821f4","html_url":"https://github.com/mutkuensert/BitmapCompression","commit_stats":null,"previous_names":["mutkuensert/bitmapcompression"],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mutkuensert%2FBitmapCompression","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mutkuensert%2FBitmapCompression/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mutkuensert%2FBitmapCompression/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mutkuensert%2FBitmapCompression/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mutkuensert","download_url":"https://codeload.github.com/mutkuensert/BitmapCompression/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238895164,"owners_count":19548554,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","android-image-compressor","android-library","bitmap","image-compression"],"created_at":"2025-02-14T18:57:11.334Z","updated_at":"2025-10-29T21:31:10.257Z","avatar_url":"https://github.com/mutkuensert.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Class Information\n```kotlin\n/**\n * @property file The file to be reduced in size. It will be overwritten with the size reduction processes.\n * @property sizeLimitBytes Max size the file can be after compression.\n * @property compressPriority Start reducing file size by scaling down or compressing.\n * @property lowerWidthLimit Stop scaling down before dropping down below this value.\n * @property lowerHeightLimit Stop scaling down before dropping down below this value.\n * @property compressionQualityDownTo Lower value means lower quality and smaller size.\n * @property scaleDownFactor Scale factor to divide width and height of image in every loop.\n */\nclass BitmapCompression(\n    private val file: File,\n    var sizeLimitBytes: Int,\n    var compressPriority: CompressPriority = CompressPriority.StartByCompress,\n    var lowerWidthLimit: Int? = null,\n    var lowerHeightLimit: Int? = null,\n    @IntRange(from = 1, to = 90)\n    var compressionQualityDownTo: Int = 50,\n    @FloatRange(from = 0.1, to = 0.9)\n    var scaleDownFactor: Float = 0.8f\n)\n```\n\n## About the class\nThe BitmapCompression class provides a utility to reduce the size of the image files \nunder a specified size limit while maintaining control over compression parameters.\n\n\n## Usage\nIn this example, size reduction starts with scaling down the file prior to compressing process, \naiming to reduce the size under 1048576 bytes and prevents scaling the image width down below 1920 pixels.\nIf the size reduction can't succeed, lowerWidthLimit is being set to a lower level and compressAndScaleDown \nfunction is invoked again so that the size can be reduced under the specified size limit.\n```kotlin\nval compression = BitmapCompression(\n    file = tempFile,\n    sizeLimitBytes = 1048576,\n    compressPriority = BitmapCompression.CompressPriority.StartByScaleDown,\n    lowerWidthLimit = 1920,\n    compressionQualityDownTo = 85\n)\n\ntry {\n    compression.compressAndScaleDown()\n} catch (exception: SizeException) {\n    compression.lowerWidthLimit = 1280\n    compression.compressAndScaleDown()\n}\n```\n\n### Static functions\nScale down a bitmap or a file preserving the aspect ratio.\n```kotlin\nval scaledDownToFullHdBitmap = BitmapCompression.scaleDownToWidth(bitmap, 1920)\n```\n\n```kotlin\nBitmapCompression.scaleDownToWidth(tempFile, 1920)\n```\n\n```kotlin\nval scaledDownToFullHdBitmap = BitmapCompression.scaleDownToHeight(bitmap, 1080)\n```\n\n```kotlin\nBitmapCompression.scaleDownToHeight(tempFile, 1080)\n```\n\n### How to use it\nYou can build the library and use it as an aar in a project.\n\n ## License\n```xml\nCopyright 2024 Mustafa Utku Ensert\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmutkuensert%2Fbitmapcompression","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmutkuensert%2Fbitmapcompression","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmutkuensert%2Fbitmapcompression/lists"}