smart-image-cropper 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.
@@ -0,0 +1,144 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ pip-wheel-metadata/
24
+ share/python-wheels/
25
+ *.egg-info/
26
+ .installed.cfg
27
+ *.egg
28
+ MANIFEST
29
+
30
+ # PyInstaller
31
+ # Usually these files are written by a python script from a template
32
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
33
+ *.manifest
34
+ *.spec
35
+
36
+ # Installer logs
37
+ pip-log.txt
38
+ pip-delete-this-directory.txt
39
+
40
+ # Unit test / coverage reports
41
+ htmlcov/
42
+ .tox/
43
+ .nox/
44
+ .coverage
45
+ .coverage.*
46
+ .cache
47
+ nosetests.xml
48
+ coverage.xml
49
+ *.cover
50
+ *.py,cover
51
+ .hypothesis/
52
+ .pytest_cache/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ target/
76
+
77
+ # Jupyter Notebook
78
+ .ipynb_checkpoints
79
+
80
+ # IPython
81
+ profile_default/
82
+ ipython_config.py
83
+
84
+ # pyenv
85
+ .python-version
86
+
87
+ # pipenv
88
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
90
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
91
+ # install all needed dependencies.
92
+ #Pipfile.lock
93
+
94
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow
95
+ __pypackages__/
96
+
97
+ # Celery stuff
98
+ celerybeat-schedule
99
+ celerybeat.pid
100
+
101
+ # SageMath parsed files
102
+ *.sage.py
103
+
104
+ # Environments
105
+ .env
106
+ .venv
107
+ env/
108
+ venv/
109
+ ENV/
110
+ env.bak/
111
+ venv.bak/
112
+
113
+ # Spyder project settings
114
+ .spyderproject
115
+ .spyproject
116
+
117
+ # Rope project settings
118
+ .ropeproject
119
+
120
+ # mkdocs documentation
121
+ /site
122
+
123
+ # mypy
124
+ .mypy_cache/
125
+ .dmypy.json
126
+ dmypy.json
127
+
128
+ # Pyre type checker
129
+ .pyre/
130
+
131
+ # IDE
132
+ .vscode/
133
+ .idea/
134
+ *.swp
135
+ *.swo
136
+
137
+ # macOS
138
+ .DS_Store
139
+
140
+ # Test images
141
+ test_images/
142
+ *.jpg
143
+ *.png
144
+ *.jpeg
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Smart Image Cropper
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,8 @@
1
+ include README.md
2
+ include LICENSE
3
+ include requirements.txt
4
+ include pyproject.toml
5
+ recursive-include smart_image_cropper *.py
6
+ recursive-exclude * __pycache__
7
+ recursive-exclude * *.py[co]
8
+ recursive-exclude * .DS_Store
@@ -0,0 +1,258 @@
1
+ Metadata-Version: 2.4
2
+ Name: smart-image-cropper
3
+ Version: 1.0.0
4
+ Summary: An intelligent image cropping library that creates smart collages
5
+ Home-page: https://github.com/giumanuz/image_cropper
6
+ Author: Giulio Manuzzi
7
+ Author-email: Your Name <your.email@example.com>
8
+ Maintainer-email: Your Name <your.email@example.com>
9
+ License: MIT
10
+ Project-URL: Homepage, https://github.com/yourusername/smart-image-cropper
11
+ Project-URL: Documentation, https://github.com/yourusername/smart-image-cropper#readme
12
+ Project-URL: Repository, https://github.com/yourusername/smart-image-cropper
13
+ Project-URL: Bug Tracker, https://github.com/yourusername/smart-image-cropper/issues
14
+ Keywords: image processing,cropping,collage,computer vision,opencv
15
+ Classifier: Development Status :: 4 - Beta
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Classifier: Operating System :: OS Independent
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.8
21
+ Classifier: Programming Language :: Python :: 3.9
22
+ Classifier: Programming Language :: Python :: 3.10
23
+ Classifier: Programming Language :: Python :: 3.11
24
+ Classifier: Topic :: Multimedia :: Graphics
25
+ Classifier: Topic :: Scientific/Engineering :: Image Processing
26
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
27
+ Requires-Python: >=3.8
28
+ Description-Content-Type: text/markdown
29
+ License-File: LICENSE
30
+ Requires-Dist: opencv-python>=4.5.0
31
+ Requires-Dist: numpy>=1.20.0
32
+ Requires-Dist: Pillow>=8.0.0
33
+ Requires-Dist: requests>=2.25.0
34
+ Provides-Extra: dev
35
+ Requires-Dist: pytest>=6.0; extra == "dev"
36
+ Requires-Dist: pytest-cov>=2.0; extra == "dev"
37
+ Requires-Dist: black>=21.0; extra == "dev"
38
+ Requires-Dist: flake8>=3.8; extra == "dev"
39
+ Requires-Dist: mypy>=0.812; extra == "dev"
40
+ Dynamic: author
41
+ Dynamic: home-page
42
+ Dynamic: license-file
43
+ Dynamic: requires-python
44
+
45
+ # Smart Image Cropper
46
+
47
+ [![PyPI version](https://badge.fury.io/py/smart-image-cropper.svg)](https://badge.fury.io/py/smart-image-cropper)
48
+ [![Python Support](https://img.shields.io/pypi/pyversions/smart-image-cropper.svg)](https://pypi.org/project/smart-image-cropper/)
49
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
50
+
51
+ An intelligent image cropping library that automatically detects objects in
52
+ images and creates optimized crops or collages. The library uses AI-powered
53
+ bounding box detection to identify the most important regions in your images and
54
+ intelligently crops them to standard aspect ratios.
55
+
56
+ ## Features
57
+
58
+ - 🎯 **Smart Object Detection**: Automatically detects important objects in
59
+ images using AI
60
+ - 🖼️ **Intelligent Cropping**: Crops images to optimal aspect ratios (4:5, 3:4,
61
+ 1:1, 4:3)
62
+ - 🎨 **Automatic Collages**: Creates beautiful collages when multiple objects
63
+ are detected
64
+ - 📐 **Aspect Ratio Optimization**: Automatically expands crops to reach target
65
+ aspect ratios
66
+ - 🔧 **Flexible Input**: Supports URLs, bytes, and PIL Images as input
67
+ - ⚡ **Fast Processing**: Efficient image processing with OpenCV
68
+ - 🐍 **Pure Python**: Easy to integrate into any Python project
69
+
70
+ ## Installation
71
+
72
+ ```bash
73
+ pip install smart-image-cropper
74
+ ```
75
+
76
+ ## Quick Start
77
+
78
+ ```python
79
+ from smart_image_cropper import SmartImageCropper
80
+ from PIL import Image
81
+
82
+ # Initialize the cropper with your API credentials
83
+ cropper = SmartImageCropper(
84
+ api_url="your-api-endpoint",
85
+ api_key="your-api-key"
86
+ )
87
+
88
+ # Method 1: Process from URL
89
+ result_bytes = cropper.process_image("https://example.com/image.jpg")
90
+
91
+ # Method 2: Process from bytes
92
+ with open("image.jpg", "rb") as f:
93
+ image_bytes = f.read()
94
+ result_bytes = cropper.process_image(image_bytes)
95
+
96
+ # Method 3: Process from PIL Image
97
+ pil_image = Image.open("image.jpg")
98
+ result_bytes = cropper.process_image(pil_image)
99
+
100
+ # Save the result
101
+ with open("cropped_result.jpg", "wb") as f:
102
+ f.write(result_bytes)
103
+ ```
104
+
105
+ ## How It Works
106
+
107
+ 1. **Object Detection**: The library sends your image to an AI-powered bounding
108
+ box detection API
109
+ 2. **Smart Selection**: Identifies the most important objects based on size and
110
+ relevance
111
+ 3. **Intelligent Processing**:
112
+ - **Single Object**: Crops and expands to the nearest standard aspect ratio
113
+ - **Multiple Objects**: Creates a collage with optimal layout
114
+ (vertical/horizontal)
115
+ 4. **Aspect Ratio Optimization**: Ensures the final result matches standard
116
+ social media formats
117
+
118
+ ## Supported Aspect Ratios
119
+
120
+ - **Portrait 4:5** (0.8) - Instagram posts
121
+ - **Portrait 3:4** (0.75) - Traditional photo format
122
+ - **Square 1:1** (1.0) - Instagram square posts
123
+ - **Landscape 4:3** (1.33) - Traditional landscape format
124
+
125
+ ## API Requirements
126
+
127
+ This library requires access to a bounding box detection API. The API should:
128
+
129
+ - Accept POST requests with JSON payload containing base64-encoded images
130
+ - Return a job ID for asynchronous processing
131
+ - Provide a status endpoint to check job completion
132
+ - Return bounding box coordinates in the format:
133
+ `{"x1": int, "y1": int, "x2": int, "y2": int}`
134
+
135
+ ### Example API Integration
136
+
137
+ ```python
138
+ # Your API should accept this format:
139
+ {
140
+ "input": {
141
+ "image": "base64-encoded-image-string"
142
+ }
143
+ }
144
+
145
+ # And return:
146
+ {
147
+ "id": "job-id-string"
148
+ }
149
+
150
+ # Status check should return:
151
+ {
152
+ "status": "COMPLETED", # or "FAILED"
153
+ "output": [
154
+ {"x1": 100, "y1": 50, "x2": 300, "y2": 250},
155
+ {"x1": 400, "y1": 100, "x2": 600, "y2": 300}
156
+ ]
157
+ }
158
+ ```
159
+
160
+ ## Advanced Usage
161
+
162
+ ### Error Handling
163
+
164
+ ```python
165
+ from smart_image_cropper import SmartImageCropper, SmartCropperError, APIError
166
+
167
+ try:
168
+ cropper = SmartImageCropper(api_url="...", api_key="...")
169
+ result = cropper.process_image("image.jpg")
170
+ except APIError as e:
171
+ print(f"API Error: {e}")
172
+ except SmartCropperError as e:
173
+ print(f"Processing Error: {e}")
174
+ ```
175
+
176
+ ### Logging
177
+
178
+ The library uses Python's logging module. Enable debug logging to see detailed
179
+ processing information:
180
+
181
+ ```python
182
+ import logging
183
+
184
+ logging.basicConfig(level=logging.INFO)
185
+ # Now you'll see detailed processing logs
186
+ ```
187
+
188
+ ## Dependencies
189
+
190
+ - **OpenCV** (`opencv-python>=4.5.0`) - Image processing
191
+ - **NumPy** (`numpy>=1.20.0`) - Numerical operations
192
+ - **Pillow** (`Pillow>=8.0.0`) - PIL Image support
193
+ - **Requests** (`requests>=2.25.0`) - HTTP API calls
194
+
195
+ ## Development
196
+
197
+ ### Setting Up Development Environment
198
+
199
+ ```bash
200
+ # Clone the repository
201
+ git clone https://github.com/yourusername/smart-image-cropper.git
202
+ cd smart-image-cropper
203
+
204
+ # Install in development mode
205
+ pip install -e ".[dev]"
206
+
207
+ # Run tests
208
+ pytest
209
+
210
+ # Format code
211
+ black .
212
+
213
+ # Type checking
214
+ mypy smart_image_cropper/
215
+ ```
216
+
217
+ ### Running Tests
218
+
219
+ ```bash
220
+ pytest tests/ -v --cov=smart_image_cropper
221
+ ```
222
+
223
+ ## Contributing
224
+
225
+ Contributions are welcome! Please feel free to submit a Pull Request. For major
226
+ changes, please open an issue first to discuss what you would like to change.
227
+
228
+ 1. Fork the repository
229
+ 2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
230
+ 3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
231
+ 4. Push to the branch (`git push origin feature/AmazingFeature`)
232
+ 5. Open a Pull Request
233
+
234
+ ## License
235
+
236
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
237
+ for details.
238
+
239
+ ## Changelog
240
+
241
+ ### v1.0.0
242
+
243
+ - Initial release
244
+ - Support for URL, bytes, and PIL Image inputs
245
+ - Automatic object detection and smart cropping
246
+ - Collage creation for multiple objects
247
+ - Aspect ratio optimization
248
+
249
+ ## Support
250
+
251
+ If you encounter any issues or have questions, please file an issue on the
252
+ [GitHub issue tracker](https://github.com/yourusername/smart-image-cropper/issues).
253
+
254
+ ## Acknowledgments
255
+
256
+ - OpenCV community for excellent image processing tools
257
+ - PIL/Pillow developers for image handling capabilities
258
+ - The Python packaging community for excellent tools and documentation
@@ -0,0 +1,262 @@
1
+ # Publishing Smart Image Cropper to PyPI
2
+
3
+ This guide will walk you through the process of publishing your Smart Image
4
+ Cropper library to PyPI (Python Package Index).
5
+
6
+ ## Prerequisites
7
+
8
+ 1. **Python 3.8+** installed
9
+ 2. **Git** installed and configured
10
+ 3. **PyPI account** - Sign up at
11
+ [https://pypi.org/account/register/](https://pypi.org/account/register/)
12
+ 4. **TestPyPI account** (optional but recommended) - Sign up at
13
+ [https://test.pypi.org/account/register/](https://test.pypi.org/account/register/)
14
+
15
+ ## Step 1: Set Up Your Development Environment
16
+
17
+ ```bash
18
+ # Clone your repository (or navigate to your project directory)
19
+ cd smart-image-cropper
20
+
21
+ # Create a virtual environment
22
+ python -m venv venv
23
+
24
+ # Activate virtual environment
25
+ # On Windows:
26
+ venv\Scripts\activate
27
+ # On macOS/Linux:
28
+ source venv/bin/activate
29
+
30
+ # Install build tools
31
+ pip install --upgrade pip setuptools wheel twine build
32
+
33
+ # Install your package in development mode
34
+ pip install -e ".[dev]"
35
+ ```
36
+
37
+ ## Step 2: Update Package Information
38
+
39
+ Before publishing, make sure to update the following files with your actual
40
+ information:
41
+
42
+ ### 1. Update `setup.py` and `pyproject.toml`
43
+
44
+ Replace placeholder information:
45
+
46
+ - `author="Your Name"`
47
+ - `author_email="your.email@example.com"`
48
+ - `url="https://github.com/yourusername/smart-image-cropper"`
49
+ - All GitHub URLs with your actual repository URLs
50
+
51
+ ### 2. Update `smart_image_cropper/__init__.py`
52
+
53
+ - Update `__author__` and `__email__` fields
54
+
55
+ ## Step 3: Test Your Package Locally
56
+
57
+ ```bash
58
+ # Run tests (if you have them)
59
+ pytest
60
+
61
+ # Check if your package can be built
62
+ python -m build
63
+
64
+ # This should create files in dist/ directory:
65
+ # - smart_image_cropper-1.0.0-py3-none-any.whl
66
+ # - smart_image_cropper-1.0.0.tar.gz
67
+ ```
68
+
69
+ ## Step 4: Validate Your Package
70
+
71
+ ```bash
72
+ # Check your package with twine
73
+ twine check dist/*
74
+
75
+ # This should show "PASSED" for all checks
76
+ ```
77
+
78
+ ## Step 5: Test on TestPyPI (Recommended)
79
+
80
+ TestPyPI is a separate instance of PyPI for testing packages.
81
+
82
+ ```bash
83
+ # Upload to TestPyPI first
84
+ twine upload --repository testpypi dist/*
85
+
86
+ # You'll be prompted for your TestPyPI credentials
87
+ # Username: your-testpypi-username
88
+ # Password: your-testpypi-password (or token)
89
+ ```
90
+
91
+ ### Test Installation from TestPyPI
92
+
93
+ ```bash
94
+ # Create a new environment to test installation
95
+ python -m venv test_env
96
+ source test_env/bin/activate # or test_env\Scripts\activate on Windows
97
+
98
+ # Install from TestPyPI
99
+ pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ smart-image-cropper
100
+
101
+ # Test that it works
102
+ python -c "from smart_image_cropper import SmartImageCropper; print('Import successful!')"
103
+ ```
104
+
105
+ ## Step 6: Publish to PyPI
106
+
107
+ Once you've tested on TestPyPI and everything works:
108
+
109
+ ```bash
110
+ # Upload to the real PyPI
111
+ twine upload dist/*
112
+
113
+ # Enter your PyPI credentials when prompted
114
+ ```
115
+
116
+ ## Step 7: Set Up API Tokens (Recommended)
117
+
118
+ For better security, use API tokens instead of username/password:
119
+
120
+ 1. Go to
121
+ [https://pypi.org/manage/account/token/](https://pypi.org/manage/account/token/)
122
+ 2. Create a new token with scope limited to your project
123
+ 3. Configure your `~/.pypirc` file:
124
+
125
+ ```ini
126
+ [distutils]
127
+ index-servers =
128
+ pypi
129
+ testpypi
130
+
131
+ [pypi]
132
+ username = __token__
133
+ password = pypi-your-api-token-here
134
+
135
+ [testpypi]
136
+ repository = https://test.pypi.org/legacy/
137
+ username = __token__
138
+ password = pypi-your-testpypi-token-here
139
+ ```
140
+
141
+ ## Step 8: Automate with GitHub Actions (Optional)
142
+
143
+ Create `.github/workflows/publish.yml`:
144
+
145
+ ```yaml
146
+ name: Publish to PyPI
147
+
148
+ on:
149
+ release:
150
+ types: [published]
151
+
152
+ jobs:
153
+ deploy:
154
+ runs-on: ubuntu-latest
155
+ steps:
156
+ - uses: actions/checkout@v3
157
+
158
+ - name: Set up Python
159
+ uses: actions/setup-python@v4
160
+ with:
161
+ python-version: "3.8"
162
+
163
+ - name: Install dependencies
164
+ run: |
165
+ python -m pip install --upgrade pip
166
+ pip install build twine
167
+
168
+ - name: Build package
169
+ run: python -m build
170
+
171
+ - name: Publish to PyPI
172
+ env:
173
+ TWINE_USERNAME: __token__
174
+ TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
175
+ run: twine upload dist/*
176
+ ```
177
+
178
+ Then add your PyPI API token as a secret in your GitHub repository:
179
+
180
+ 1. Go to your repo settings → Secrets and variables → Actions
181
+ 2. Add a new secret named `PYPI_API_TOKEN` with your token value
182
+
183
+ ## Step 9: Update Version for Future Releases
184
+
185
+ For subsequent releases:
186
+
187
+ 1. **Update version number** in:
188
+
189
+ - `setup.py`
190
+ - `pyproject.toml`
191
+ - `smart_image_cropper/__init__.py`
192
+
193
+ 2. **Clean previous builds**:
194
+
195
+ ```bash
196
+ rm -rf dist/ build/ *.egg-info/
197
+ ```
198
+
199
+ 3. **Build and upload new version**:
200
+ ```bash
201
+ python -m build
202
+ twine upload dist/*
203
+ ```
204
+
205
+ ## Common Issues and Solutions
206
+
207
+ ### Issue: Package name already exists
208
+
209
+ - Choose a different name or add a prefix/suffix
210
+ - Update the `name` field in `setup.py` and `pyproject.toml`
211
+
212
+ ### Issue: Upload fails with authentication error
213
+
214
+ - Make sure you're using the correct credentials
215
+ - Try using API tokens instead of username/password
216
+ - Check if 2FA is enabled on your account
217
+
218
+ ### Issue: "File already exists" error
219
+
220
+ - You're trying to upload the same version twice
221
+ - Update the version number and rebuild
222
+
223
+ ### Issue: Import errors after installation
224
+
225
+ - Check that all dependencies are correctly specified
226
+ - Verify the package structure matches the imports
227
+
228
+ ## Verification After Publishing
229
+
230
+ 1. **Check your package page**: `https://pypi.org/project/smart-image-cropper/`
231
+ 2. **Test installation**:
232
+ ```bash
233
+ pip install smart-image-cropper
234
+ python -c "from smart_image_cropper import SmartImageCropper; print('Success!')"
235
+ ```
236
+ 3. **Test in a fresh environment** to ensure all dependencies are properly
237
+ specified
238
+
239
+ ## Best Practices
240
+
241
+ 1. **Always test on TestPyPI first**
242
+ 2. **Use semantic versioning** (MAJOR.MINOR.PATCH)
243
+ 3. **Keep detailed changelog** in README.md
244
+ 4. **Use API tokens** instead of passwords
245
+ 5. **Automate with CI/CD** for consistent releases
246
+ 6. **Tag your releases** in Git:
247
+ ```bash
248
+ git tag v1.0.0
249
+ git push origin v1.0.0
250
+ ```
251
+
252
+ ## Resources
253
+
254
+ - [PyPI Official Packaging Tutorial](https://packaging.python.org/tutorials/packaging-projects/)
255
+ - [Twine Documentation](https://twine.readthedocs.io/)
256
+ - [Setuptools Documentation](https://setuptools.readthedocs.io/)
257
+ - [Python Packaging User Guide](https://packaging.python.org/)
258
+
259
+ ---
260
+
261
+ 🎉 **Congratulations!** Your Smart Image Cropper library is now available for
262
+ the world to use via `pip install smart-image-cropper`!