Tree [r5] /
History



File Date Author Commit
INSTALL 2009-11-06 mohanphy [r4] adding installation instruction file for autocrop
README 2009-11-06 mohanphy [r5] adding readme file for autocrop
autocrop.c 2009-11-06 mohanphy [r2] adding source file for autocrop
config.m4 2009-11-06 mohanphy [r3] adding configuration file for autocrop
php_autocrop.h 2009-11-06 mohanphy [r1] adding header file for autocrop

Read Me

What is AutoCrop?

AutoCrop is a PHP Extension based on OpenCV Library developed by Intel(For More info about OpenCV : http://opencv.willowgarage.com/). This extension provides a PHP implementation of the OpenCV library. Currently the extension comes with a new function. Using this function you can resize a hotograph in the following sizes: 75x75, 150x150 and 450x450.

Why we need AutoCrop?

Many times you may need to resize image files to a common size, either for uploading to a web site, sending to another device with a small screen, to scale them down to a smaller size, or for some other purpose. In BharatMatrimony the end-user uploads his/her picture and someone in the Profile Validation Team (verify this?), crops this picture to get a head-shot of the person and saves this in the following sizes: 75x75, 150x150 and 450x450. We don't want to do it by Profile Validation Team manually. We want to do it automatically within our application, Just by calling a php function that will detect the face in the end-user uploaded picture and crop the picture in the following size :75x75, 150x150 and 450x450 and has to save specified output path. 

To give solution, We have developed a PHP extension for automatic cropping of photographs using OpenCV Library. AutoCropping lets user crop photographs automatically within their php code. It has a new function it does the job automatically thus reducing the time spent on uploading a photograph. Currently it will crop the following size :75x75, 150x150 and 450x450 only.

How do I Install AutoCrop?

Please free to see the INSTALL file comes with AutoCrop.

 
How to Write a PHP Script for AutoCrop?

Before you start writing php script make sure you have to edit your php.ini file to specify the path of "haar training" xml file.

autocrop.cascade_path=/path_to_OpenCV/data/haarcascades/haarcascade_frontalface_alt.xml

For example, The opencv will be installed in /usr/local/share/opencv for me and all the important facedetection training files known as "haar training" can be found in haarcascades folder in xml format(/usr/local/share/opencv/data/haarcascades/).

Sample Code :

<?php

//If you wish to crop all three size 75x75,150x150 and 450x450

$input_image="rajini.jpg"
$out_75x75="rajini75x75.jpg"
$out_150x150="rajini150x150.jpg"
$out_450x450="rajini450x450.jpg"

/*If cropping successfull it return true. In case of failure return NULL and logs error message reason for failure*/

$ret=autocrop_image($input_image,$out_75x75,$out_150x150,$out_450x450);

	if(!$ret){
		echo "Failed to Crop the Image\n";
	} else {
		echo "Croping Successfull";
	}

?>


What about gif file?

OpenCV does not support gif format, AutoCrop handles it different way. If you call autocrop_image(), first it will checks whether the file format is gif of jpg(or Jpeg). If it is gif, it will create a new jpg file from orginal gif(using ImageMagic) file and do the croping and saves the output file in jpg format and deletes the intermeditate gif file. All the steps are take care of autocrop itself by automatically. We no need worry about the file format.

Need help? Have Questions?
Feel free to send your question at mohan.l@consim.com. We'd love to help you out.

Maintainer:
Mohan L        mohan.l@consim.com