Pixslim 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pixslim-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,115 @@
1
+ Metadata-Version: 2.4
2
+ Name: Pixslim
3
+ Version: 1.0.0
4
+ Summary: A lightweight Python package for compressing JPG, JPEG, and PNG images.
5
+ Author: Fatemeh SHM
6
+ License: MIT
7
+ Keywords: image,compress,compression,jpg,jpeg,png,pillow
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Topic :: Multimedia :: Graphics
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Requires-Python: >=3.9
20
+ Description-Content-Type: text/markdown
21
+ Requires-Dist: Pillow>=10.0.0
22
+
23
+ # PixSlim
24
+
25
+ **PixSlim** is a lightweight and easy-to-use Python package for compressing **JPG**, **JPEG**, and **PNG** images while trying to reach a target file size.
26
+
27
+ ## ✨ Features
28
+
29
+ - 📦 Compress JPG, JPEG, and PNG images
30
+ - 🎯 Target file size in KB
31
+ - 🖼️ Automatically reduces image dimensions if needed
32
+ - ⚡ Simple and beginner-friendly API
33
+ - 🐍 Built with Pillow
34
+
35
+ ## Installation
36
+
37
+ ```bash
38
+ pip install pixslim
39
+ ```
40
+
41
+ ## Requirements
42
+
43
+ - Python 3.9+
44
+ - Pillow
45
+
46
+ ## Usage
47
+
48
+ ```python
49
+ from pixslim import Compressor
50
+
51
+ compressor = Compressor(target_kb=500)
52
+
53
+ result = compressor.compress(
54
+ "photo.png",
55
+ "photo_small.png"
56
+ )
57
+
58
+ print(result)
59
+ ```
60
+
61
+ Example output:
62
+
63
+ ```python
64
+ {
65
+ "original_kb": 1356.42,
66
+ "final_kb": 492.18,
67
+ "reduction_percent": 63.71,
68
+ "quality": None,
69
+ "size": (1920, 1080)
70
+ }
71
+ ```
72
+
73
+ ## Supported Formats
74
+
75
+ | Input | Output |
76
+ |--------|--------|
77
+ | JPG | JPG |
78
+ | JPEG | JPEG |
79
+ | PNG | PNG |
80
+
81
+ ## Parameters
82
+
83
+ ### Compressor(target_kb=500)
84
+
85
+ | Parameter | Type | Description |
86
+ |----------|------|-------------|
87
+ | target_kb | int | Desired maximum file size in KB |
88
+
89
+ ### compress(input_file, output_file)
90
+
91
+ | Parameter | Type | Description |
92
+ |----------|------|-------------|
93
+ | input_file | str | Input image path |
94
+ | output_file | str | Output image path |
95
+
96
+ ## Example
97
+
98
+ ```python
99
+ from pixslim import Compressor
100
+
101
+ compressor = Compressor(target_kb=300)
102
+
103
+ compressor.compress(
104
+ "image.jpg",
105
+ "image_small.jpg"
106
+ )
107
+ ```
108
+
109
+ ## License
110
+
111
+ This project is licensed under the MIT License.
112
+
113
+ ##Author
114
+
115
+ **Fatemeh SHM**
@@ -0,0 +1,3 @@
1
+ from .compressor import compressor
2
+
3
+ __version__="1.0.0"
@@ -0,0 +1,88 @@
1
+ from PIL import Image
2
+ import os
3
+
4
+
5
+ class compressor:
6
+ """Compress JPG, JPEG and PNG images.
7
+ 🌼Reducing file size🌼"""
8
+
9
+ def __init__(self, target_kb=500):
10
+ self.target_kb = target_kb
11
+
12
+ def compress(self, input_file, output_file):
13
+ try:
14
+ image = Image.open(input_file)
15
+ except Exception as e:
16
+ raise ValueError(f"Cannot open image: {e}")
17
+
18
+ ext = os.path.splitext(output_file)[1].lower()
19
+
20
+ if ext not in (".jpg", ".jpeg", ".png"):
21
+ raise ValueError("Only JPG, JPEG and PNG files are supported.")
22
+
23
+ # JPEG باید RGB باشد
24
+ if ext in (".jpg", ".jpeg") and image.mode != "RGB":
25
+ image = image.convert("RGB")
26
+
27
+ original_kb = os.path.getsize(input_file) / 1024
28
+ quality = 95
29
+
30
+ while True:
31
+
32
+ if ext in (".jpg", ".jpeg"):
33
+ image.save(
34
+ output_file,
35
+ format="JPEG",
36
+ optimize=True,
37
+ quality=quality
38
+ )
39
+
40
+ else: # PNG
41
+ image.save(
42
+ output_file,
43
+ format="PNG",
44
+ optimize=True,
45
+ compress_level=9
46
+ )
47
+
48
+ final_kb = os.path.getsize(output_file) / 1024
49
+
50
+ if final_kb <= self.target_kb:
51
+ break
52
+
53
+ # کاهش کیفیت فقط برای JPEG
54
+ if ext in (".jpg", ".jpeg") and quality > 20:
55
+ quality -= 5
56
+ continue
57
+
58
+ # اگر هنوز حجم زیاد بود، اندازه تصویر را کم کن
59
+ width, height = image.size
60
+
61
+ if width < 100 or height < 100:
62
+ break
63
+
64
+ image = image.resize(
65
+ (int(width * 0.9), int(height * 0.9)),
66
+ Image.Resampling.LANCZOS
67
+ )
68
+
69
+ reduction = (1 - final_kb / original_kb) * 100
70
+
71
+ return {
72
+ "original_kb": round(original_kb, 2),
73
+ "final_kb": round(final_kb, 2),
74
+ "reduction_percent": round(reduction, 2),
75
+ "quality": quality if ext in (".jpg", ".jpeg") else None,
76
+ "size": image.size
77
+ }
78
+
79
+ if __name__ == "__main__":
80
+
81
+ compressor = compressor(target_kb=500)
82
+
83
+ result = compressor.compress(
84
+ r"C:\Users\Almahdi Laptop\OneDrive\Pictures\f.png",
85
+ r"C:\Users\Almahdi Laptop\OneDrive\Pictures\photo_small.png"
86
+ )
87
+
88
+ print(result)
@@ -0,0 +1,115 @@
1
+ Metadata-Version: 2.4
2
+ Name: Pixslim
3
+ Version: 1.0.0
4
+ Summary: A lightweight Python package for compressing JPG, JPEG, and PNG images.
5
+ Author: Fatemeh SHM
6
+ License: MIT
7
+ Keywords: image,compress,compression,jpg,jpeg,png,pillow
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Topic :: Multimedia :: Graphics
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Requires-Python: >=3.9
20
+ Description-Content-Type: text/markdown
21
+ Requires-Dist: Pillow>=10.0.0
22
+
23
+ # PixSlim
24
+
25
+ **PixSlim** is a lightweight and easy-to-use Python package for compressing **JPG**, **JPEG**, and **PNG** images while trying to reach a target file size.
26
+
27
+ ## ✨ Features
28
+
29
+ - 📦 Compress JPG, JPEG, and PNG images
30
+ - 🎯 Target file size in KB
31
+ - 🖼️ Automatically reduces image dimensions if needed
32
+ - ⚡ Simple and beginner-friendly API
33
+ - 🐍 Built with Pillow
34
+
35
+ ## Installation
36
+
37
+ ```bash
38
+ pip install pixslim
39
+ ```
40
+
41
+ ## Requirements
42
+
43
+ - Python 3.9+
44
+ - Pillow
45
+
46
+ ## Usage
47
+
48
+ ```python
49
+ from pixslim import Compressor
50
+
51
+ compressor = Compressor(target_kb=500)
52
+
53
+ result = compressor.compress(
54
+ "photo.png",
55
+ "photo_small.png"
56
+ )
57
+
58
+ print(result)
59
+ ```
60
+
61
+ Example output:
62
+
63
+ ```python
64
+ {
65
+ "original_kb": 1356.42,
66
+ "final_kb": 492.18,
67
+ "reduction_percent": 63.71,
68
+ "quality": None,
69
+ "size": (1920, 1080)
70
+ }
71
+ ```
72
+
73
+ ## Supported Formats
74
+
75
+ | Input | Output |
76
+ |--------|--------|
77
+ | JPG | JPG |
78
+ | JPEG | JPEG |
79
+ | PNG | PNG |
80
+
81
+ ## Parameters
82
+
83
+ ### Compressor(target_kb=500)
84
+
85
+ | Parameter | Type | Description |
86
+ |----------|------|-------------|
87
+ | target_kb | int | Desired maximum file size in KB |
88
+
89
+ ### compress(input_file, output_file)
90
+
91
+ | Parameter | Type | Description |
92
+ |----------|------|-------------|
93
+ | input_file | str | Input image path |
94
+ | output_file | str | Output image path |
95
+
96
+ ## Example
97
+
98
+ ```python
99
+ from pixslim import Compressor
100
+
101
+ compressor = Compressor(target_kb=300)
102
+
103
+ compressor.compress(
104
+ "image.jpg",
105
+ "image_small.jpg"
106
+ )
107
+ ```
108
+
109
+ ## License
110
+
111
+ This project is licensed under the MIT License.
112
+
113
+ ##Author
114
+
115
+ **Fatemeh SHM**
@@ -0,0 +1,9 @@
1
+ README.md
2
+ pyproject.toml
3
+ Pixslim/__init__.py
4
+ Pixslim/compressor.py
5
+ Pixslim.egg-info/PKG-INFO
6
+ Pixslim.egg-info/SOURCES.txt
7
+ Pixslim.egg-info/dependency_links.txt
8
+ Pixslim.egg-info/requires.txt
9
+ Pixslim.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ Pillow>=10.0.0
@@ -0,0 +1 @@
1
+ Pixslim
@@ -0,0 +1,93 @@
1
+ # PixSlim
2
+
3
+ **PixSlim** is a lightweight and easy-to-use Python package for compressing **JPG**, **JPEG**, and **PNG** images while trying to reach a target file size.
4
+
5
+ ## ✨ Features
6
+
7
+ - 📦 Compress JPG, JPEG, and PNG images
8
+ - 🎯 Target file size in KB
9
+ - 🖼️ Automatically reduces image dimensions if needed
10
+ - ⚡ Simple and beginner-friendly API
11
+ - 🐍 Built with Pillow
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ pip install pixslim
17
+ ```
18
+
19
+ ## Requirements
20
+
21
+ - Python 3.9+
22
+ - Pillow
23
+
24
+ ## Usage
25
+
26
+ ```python
27
+ from pixslim import Compressor
28
+
29
+ compressor = Compressor(target_kb=500)
30
+
31
+ result = compressor.compress(
32
+ "photo.png",
33
+ "photo_small.png"
34
+ )
35
+
36
+ print(result)
37
+ ```
38
+
39
+ Example output:
40
+
41
+ ```python
42
+ {
43
+ "original_kb": 1356.42,
44
+ "final_kb": 492.18,
45
+ "reduction_percent": 63.71,
46
+ "quality": None,
47
+ "size": (1920, 1080)
48
+ }
49
+ ```
50
+
51
+ ## Supported Formats
52
+
53
+ | Input | Output |
54
+ |--------|--------|
55
+ | JPG | JPG |
56
+ | JPEG | JPEG |
57
+ | PNG | PNG |
58
+
59
+ ## Parameters
60
+
61
+ ### Compressor(target_kb=500)
62
+
63
+ | Parameter | Type | Description |
64
+ |----------|------|-------------|
65
+ | target_kb | int | Desired maximum file size in KB |
66
+
67
+ ### compress(input_file, output_file)
68
+
69
+ | Parameter | Type | Description |
70
+ |----------|------|-------------|
71
+ | input_file | str | Input image path |
72
+ | output_file | str | Output image path |
73
+
74
+ ## Example
75
+
76
+ ```python
77
+ from pixslim import Compressor
78
+
79
+ compressor = Compressor(target_kb=300)
80
+
81
+ compressor.compress(
82
+ "image.jpg",
83
+ "image_small.jpg"
84
+ )
85
+ ```
86
+
87
+ ## License
88
+
89
+ This project is licensed under the MIT License.
90
+
91
+ ##Author
92
+
93
+ **Fatemeh SHM**
@@ -0,0 +1,46 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "Pixslim"
7
+ version = "1.0.0"
8
+ description = "A lightweight Python package for compressing JPG, JPEG, and PNG images."
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = { text = "MIT" }
12
+
13
+ authors = [
14
+ { name = "Fatemeh SHM" }
15
+ ]
16
+
17
+ keywords = [
18
+ "image",
19
+ "compress",
20
+ "compression",
21
+ "jpg",
22
+ "jpeg",
23
+ "png",
24
+ "pillow"
25
+ ]
26
+
27
+ classifiers = [
28
+ "Development Status :: 4 - Beta",
29
+ "Intended Audience :: Developers",
30
+ "License :: OSI Approved :: MIT License",
31
+ "Programming Language :: Python :: 3",
32
+ "Programming Language :: Python :: 3.9",
33
+ "Programming Language :: Python :: 3.10",
34
+ "Programming Language :: Python :: 3.11",
35
+ "Programming Language :: Python :: 3.12",
36
+ "Operating System :: OS Independent",
37
+ "Topic :: Multimedia :: Graphics",
38
+ "Topic :: Software Development :: Libraries :: Python Modules"
39
+ ]
40
+
41
+ dependencies = [
42
+ "Pillow>=10.0.0"
43
+ ]
44
+
45
+ [tool.setuptools.packages.find]
46
+ include = ["Pixslim"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+