Differentiating between a selfie and other images using php or laravel

I have a site that allows users to upload images. My challenge is that i only want to allow users to upload selfies only. If a users uploads a picture that is not a selfie, an error message should be displayed. Does any one here knows how i can achieve that? I have searched in the internet as well as in books but i haven’t found anything to do with this. i know its possible, i just don know how. I will be more than grateful if you guys will give me a lead on how i can achieve this. Thanks in advance.

There was some interesting image recognition software discussed here.

You could use some face recognition software; I did some work with Liuliu and php.

it might be because this has nothing to do with PHP (or any other programming language). to determine whether a picture is a selfie, you first need to set some rules that must be met for a selfie. then you could train an AI for those rules and then you would only have to feed the image to this AI and it tells you, if the image is a selfie or not.

Can you give a link please?

Just edited my post as you were repyling!

See the link in post #3 of the topic I linked.

Thenks for the quick reply. Can i use php or laravel for the AI?

no. PHP’s the wrong tool for that.

Can you please tell me which is the write language for that, considering that the whole my site is based on laravel 5.2? thenks in advance.

you don’t want to write an AI! use an existing one. (e.g. this one does something similar to yours, only with trees)

Have seen it. Let me go through it and see whether it will help. Thenks for that link…

The most interesting part here is the belief that AI is something trivial, like ORM or a shopping cart, that can be simply written or adopted from existing code.

Speaking of the task, I could think of an AI that can tell a human portrait from other image, but specifically a selfie…


There are AIs out there that can detect faces that have an API like Watson.
But distinguishing a portrait from a self portrait is quite specific.
Watson is specific in some areas more than others. For example, show it a dog, it knows it’s a dog, but not which breed. Show it a butterfly, it tells you which species of butterfly.
With people/faces it will try to guess age and gender and also has a celebrity match feature.

But it does have a “Train” feature where I guess you can train it to identify more specific types of images in a category.

1 Like

The only fool proof way is the OP will have to check photo - or employ somebody else to do it

1 Like

That’s what I was thinking.

Require a part of an arm or “selfie-stick” to be in the photo?

Wouldn’t work for “set timer and put camera on a shelf” shots. And no way of knowing if such a selfie is truly of who is submitting it, only that it apparently is a selfie of someone.

Have a look at openCV its not php but is one of the most powerful image processing libraries. They have also tons of interfaces to it would be worth checking out.

Also here is a binding for OpenCV using php

1 Like

It would have a hard time knowing if the picture was just a portrait pic with someone else taking the picture, or what happens if there are 2 people in the picture i.e. This is me and (celebrity, wife, friend, whoever). Does that matter? When you say Selfie do you mean camera at arms length of the person taking the picture or is a portrait pic/passport photo still ok?

What are you trying to achieve? could it be user moderated?

First of all thenks alot for your reply. I have a website with a tab/ link of Selfie only. I want users to upload selfies only on that page. May be i can say arm length of maybe 1.5m length and it must be human faces only. I hope you are getting the concept.

Thenks for your reply. Will check on that.