Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8356703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:15:57+00:00 2026-06-09T10:15:57+00:00

So I wrote a Unit Test to compare cropped images (using imagemagick) in PHP.

  • 0

So I wrote a Unit Test to compare cropped images (using imagemagick) in PHP. The test works, but i’ve been running into problems when it comes to comparing a large number of images at a time. Depending on the time the image is created at, each image receives a timestamp that is embedded directly into the raw data. I’ve been using a regular expression to pull out that timestamp right before comparing the files but it appears as though every once in a while, one of the image files will have additional raw data in it even though they’re exactly the same.

To give an example, here’s the result from one of my tests (note, i’m comparing the binary data of the images as a string):

ImageTest::testAutoCrop

Failed asserting that two strings are equal.

— Expected

+++ Actual

@@ @@

?n??m?

-?F sO=f??????????^???????w??>

                          ?(???/o????M)???o%tEXt??%tEXt

+?F sO=f??????????^???????w??>

                          ?(???/o????M)???o%tEXt

As you can see….the only difference between these two files is that the expected image has this additional string in it: "?%tEXt".

Can someone help me understand what this random piece of data represents? That will help me figure out how to modify my unit test so that issues like this won’t happen anymore.

Thanks,

Malcolm

PS: Please let me know if I need to provide more information.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:15:59+00:00Added an answer on June 9, 2026 at 10:15 am

    So I eventually came up with a solution to this issue. Couple things to clarify:

    1. The reason why I was making unit tests is because our imageservice web application ( PHP ) uses Imagemagick to handle all image processing, manipulation , conversion of HTML to image, and PDF to image ( jpg,png,gif, all non cmyk, pdf ) conversions that happen on our main website. Needed to make sure that as we added new features to this image service application, there were enough tests in place to ensure that everything still functioned correctly.

    2. The string data that we saw in each image ( aka: ?%tEXt ) is the image’s exif data. ( http://en.wikipedia.org/wiki/Exchangeable_image_file_format ) in order to compare pictures ( suggestion taken from David Andersson’s reply ( https://stackoverflow.com/users/904933/david-andersson ) we needed to completely strip all comment data out of the image along with the creation date time stamp / modified on info. That way you’re dealing with simply an image and no other type of meta data. We did that with the following function:

    
    protected static function _removeTimeStamp( $string, $pdf = false ) {
    
      /* Note: Assume $string parameter is the image you're planning on cleaning in string format. */
    
      /* If you're working with a pdf, you need to remove the CreationDate using regex from the string representation. */
      if ( $pdf )
        return preg_replace( '/(CreationDate[^)]+)/', '', $string );
    
      /* Create a path for the temporary image we're going to need to create that will hold the exif free image */
      $strip_tmp = 'test/strip_tmp';
    
      /* write contents of string to temp string file */
      file_put_contents( $strip_tmp, $string );
    
      /* this will remove all exif data along with the date:create and date:modify properties from the image */
      exec( 'convert ' . $strip_tmp . ' -strip +set date:create +set date:modify ' . $strip_tmp . ' 2> /dev/null' ); 
    
      /* get the string representation of the new "cleaned" image */
      $result = file_get_contents( $strip_tmp ); 
    
      /* delete the temp file */
      unlink( $strip_tmp ); 
    
      /* return the cleaned string */
      return $result;
    
    } // _removeTimeStamp
    

    This was run on each image before comparing them to each other ( in String format ). Hopefully this helps someone in the future who might be doing something similar.

    I plan on writing a blog post about this in more detail to show how I took care of a number of other tests. When I do I will update this question with the link in either the comments or this answer. Hope this helps someone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote an unit-test using MSTest for my Application which uses functionality from a
I wrote an unit-test for an activity which finally puts a message into a
I would like to write the unit test for a text parser class but
I wrote unit test (JUnit 4) that performs some logic and writes result to
I have a method calling localtime that I wrote a unit test for. I
I wrote a unit test for my code. The code looks like the following:
I'd like to start using unit tests, but I'm having a hard time understanding
I am trying to unit test an action filter I wrote. I want to
I wrote a unit test checking whether initial data is loaded correctly. However the
I want to write a unit test for a Django manage.py command that does

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.