Complete case study: watermark detection, remove and place a new watermark- Part II

Like I said in the previous article “Complete case study: watermark replacement – part I” about replacing an old or outdated watermark, this task is not quite trivial but more likely boring and very time-consuming.

Anyway…let’s continue. I have now separated all images by:

  • logo in the center
  • multiple logos all over.

I will try to process the images that have the logo in the center. In this group, I have a little bit over 40.000 images.

I will use for this purpose BatchInpaint which is capable of removing objects of the image and refill the spot after that.

screenshot4

**Please note that I am not an affiliate of this software or related in any way with it.

Anyway, this little piece of software needs all images to have the same size, so I will have to resize all image using some criteria like original size and aspect ratio and group them by the cropped size for further batch processing.

I used a custom PHP script and Phil Brown’s ImageManipulator class.

You can use this to get a nice list of your files which then you can process using the image manipulator class depending on your needs.

I finally get 15 groups of different sizes of images. So I started creating the layer for the logo to be removed in BatchInpaint.

This took me around 2 hours to complete the 15 size layers and remove the watermark object.

The batch process did a great job, but there were some imperfections. This is no problem since I will put the new watermark on top of the imperfection that BatchInpaint left.

A 50% transparency will do just fine. I used FotoSizer to apply the new watermark but there are lots of software around the web including some great classes that you can use.

Now that I have removed all watermark on my images and placed the new one, I have to roll back the folder structure and the image naming. This is an easy task. Just get the ID from the database and search for the image with the same name.  When you find the image just use PHP rename built-in function. It will create the image using the original file and folder naming. Remember that I stored the folder structure when I first move the images to one folder.

Next, I used a free PHP class called php-simple-watermark to place a semi-transparent watermark over all images.

I first used FotoSizer, the professional edition to do the job. But did not do a good job since the images were different size and orientation. The watermark was always the same size and on some images, it was wider than the image itself.

I looked for a PHP class that solves this issue in an elegant way and the “PHP class” did it out of the box. The watermark was resized proportionally to the image width. I really liked it.

rollback folders paragraph

After all this, I realize that size in kb of all my images has doubled. I really don’t know why and when this happened, but I more interested in finding a solution to compress all my images then searching for the step that made them explode in size.

I end up testing ImageMagick, but I first glace I did not find the way to do it. So I returned to my good all FotoSizer. I selected “Original Size” for the image size and decreased quality to 90% (you will really not notice any difference in this and you could also try 90% if you concern about space or loading time). I then selected “Same output” and overwrite the original images (you can make a backup os select a different output folder if you are just testing). This how I reduced by half the image size in kb.

All good now. Time to deliver the images. I hope you like this article. I know there are some better ways to achieve the same result, but this was the best I could find at the moment and given the short time to deliver.

You think you can remove the watermark and replace it in a better and faster manner. Please let me know how in a comment.

Later edit: Now that I have to remove the watermark and delivered the images, the client lets me know that he has another set of 50.000 images to process. So here we go again 🙂

One thought on “Complete case study: watermark detection, remove and place a new watermark- Part II”

Leave a Reply

Your email address will not be published. Required fields are marked *

3 + 20 =