Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Perfect for profile picture processing for your website or batch work for ID cards, autocrop will output images centered around the biggest face detected.
Simple!
pip install autocrop
Autocrop can be used from the command line or directly from Python API.
Import the Cropper
class, set some parameters (optional), and start cropping.
The crop
method accepts filepaths or np.ndarray
, and returns Numpy arrays. These are easily handled with PIL or Matplotlib.
from PIL import Image
from autocrop import Cropper
cropper = Cropper()
# Get a Numpy array of the cropped image
cropped_array = cropper.crop('portrait.png')
# Save the cropped image with PIL if a face was detected:
if cropped_array:
cropped_image = Image.fromarray(cropped_array)
cropped_image.save('cropped.png')
Further examples and use cases are found in the accompanying Jupyter Notebook.
usage: [-h] [-o OUTPUT] [-i INPUT] [-w WIDTH] [-H HEIGHT] [-e EXTENSION] [-v]
Automatically crops faces from batches of pictures
optional arguments:
-h, --help
Show this help message and exit
-o, --output, -p, --path
Folder where cropped images will be placed.
Default: current working directory
-r, --reject
Folder where images without detected faces will be placed.
Default: same as output directory
-i, --input
Folder where images to crop are located.
Default: current working directory
-w, --width
Width of cropped files in px. Default=500
-H, --height
Height of cropped files in px. Default=500
--facePercent
Zoom factor. Percentage of face height to image height.
-e, --extension
Enter the image extension which to save at output.
Default: Your current image extension
-v, --version
Show program's version number and exit
pics
folder, resize them to 400 px squares, and output them in the crop
directory:
autocrop -i pics -o crop -w 400 -H 400
.crop
.reject
directory:
autocrop -i pics -o crop -r reject -w 400 -H 400
.png
:
autocrop -i pics -o crop -w 400 -H 400 -e png
If no output folder is added, asks for confirmation and destructively crops images in-place.
You can use autocrop to detect faces in frames extracted from a video. A great way to perform the frame extraction step is with ffmpeg
:
mkdir frames faces
# Extract one frame per second
ffmpeg -i input.mp4 -filter:v fps=fps=1/60 frames/ffmpeg_%0d.bmp
# Crop faces as jpg
autocrop -i frames -o faces -e jpg
The following file types are supported:
.eps
).gif
) (only the first frame of an animated GIF is used).j2k
, .j2p
, .jp2
, .jpx
).jpeg
, .jpg
, .jpe
).im
).icns
).msp
).pcx
).png
).pbm
, .pgm
, .ppm
).sgi
).spi
).tga
).tif
, .tiff
).webp
).bmp
, .dib
).ico
).xbm
)In some cases, you may wish the package directly, instead of through PyPI:
cd ~
git clone https://github.com/leblancfg/autocrop
cd autocrop
pip install .
Development of a conda-forge
package for the Anaconda Python distribution is currently stalled due to the complexity of setting up the workflow with OpenCV. Please leave feedback on issue #7 to see past attempts if you are insterested in helping out!
Best practice for your projects is of course to use virtual environments. At the very least, you will need to have pip installed.
Autocrop is currently being tested on:
Check out:
Adapted from:
Although autocrop is essentially a CLI wrapper around a single OpenCV function, it is actively developed. It has active users throughout the world.
If you would like to contribute, please consult the contribution docs.
FAQs
Automatically crops faces from batches of pictures
We found that autocrop demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.