|
|
| |
1. Example? Documentation? |
|
Reply |
|
|
 Michael Schulz | 2010-09-01 11:10:00 |
An example would be nice as well as some documentation (I don't buy into the notion that the (uncommented) source is documentation enough).
By the way: A clean code (e.g. without hardcoded leftovers from development like "$diff = new imagediff('holly-marie-combs-09.jpg', '3.jpg');") would be appreciated.
But I really like the idea of the class *thumbs up*, great thinking. |
| |
2. Re: Example? Documentation? |
|
Reply |
|
|
 Pashkov Denis Igorevich | 2010-10-10 10:10:48 - In reply to message 1 from Michael Schulz |
| thank's |
| |
3. Re: Example? Documentation? |
|
Reply |
|
|
 Gerald Fullam | 2011-05-06 23:15:15 - In reply to message 1 from Michael Schulz |
Here is how I worked with it:
Step 1: Include the class in your main PHP file
<? include 'img_class.php'; ?>
Step 2: Input your images dynamically and/or inline
// Dynamic image input gets img path from query string
// ex. "?src=IMAGEPATH.jpg"
$testImg = $_GET['src'];
// Invoke image class with one inline image
// (which is the image I am always comparing to in my script)
// and the dynamic image path
$diff = new imagediff('Mugshot_view.gif', $testImg);
// Do something with the comparison result
// You can print it
print ($diff->diff() * 100 ).'%';
// Or store it in a variable for use elsewhere
$similarity = ($diff->diff() * 100).'%'
/======================================================/
I modified the class to work for my needs. One problem I found was that I needed to use a URL of an image, not just an local path. I modified the class by removing the realpath() functions and the Exception:
function __construct($img1, $img2)
{
$this->image1['path'] = $img1;
$this->image2['path'] = $img2;
/* BYPASS EXCEPTION
if($this->image1['path'] === false || $this->image2['path'] === false)
{
throw new Exception('Image "'.htmlspecialchars( $this->image1 ? $img2 : $img1 ).'" not found!');
}
else
{
$this->image1['type'] = $this->imagetyte($this->image1['path']);
$this->image2['type'] = $this->imagetyte($this->image2['path']);
}
*/
/* TRY THIS INSTEAD OF EXCEPTION */
$this->image1['type'] = $this->imagetyte($this->image1['path']);
$this->image2['type'] = $this->imagetyte($this->image2['path']);
/* END BYPASS */
}
/======================================================/
Another problem was that the image URLs I was using were dynamically generated images that did not have file extensions. Looking for the mime type is the more reliable alternative: I invoked the getimagesize() function which returns the mime type as well. See changes below:
private function imagetyte($imgname)
{
$file_info = getimagesize($imgname);
if(!empty ($file_info['mime']))
{
$filetype = preg_replace('/image\//','',$file_info['mime']);
$func = 'imagecreatefrom' . $filetype; |
| |
4. Re: Example? Documentation? |
|
Reply |
|
|
 Gerald Fullam | 2011-05-06 23:16:34 - In reply to message 1 from Michael Schulz |
| BTW I love the class concept. Very effective. Thank you for making it. :) |
|