SkillAgentSearch skills...

Alt

[EXPERIMENTAL] Facebook-like automatic alternative (alt) text for images using object detection with pre-trained model.

Install / Use

/learn @ankitpokhrel/Alt

README

alt  Build Status

This project is no longer maintained.

Automatic alternative (alt) text for images using object detection with pre-trained model.

Overview

A very simple PHP library to generate alternative (alt) text for images using pre-trained tensorflow model to detect objects in an image. These texts can provide context about image to visitors who are unable to see images in their browser for whatever reasons. Alt texts can also be picked up by screen readers to convert it to speech, thus, providing additional context to visually impaired people and enhancing our user experience.

This nifty little tool is inspired by facebook alt text generation process.

Example

| | | | | |-|-|-|-| | <img src="tests/images/workplace.jpg" width="300" alt="Image may contain: cup, potted plant, laptop"> <br>Image may contain: cup, potted, laptop | <img src="tests/images/people.jpg" width="300" alt="Image may contain: 6 person, cup, laptop"> <br>Image may contain: 6 person, cup, laptop | <img src="tests/images/street.jpg" width="300" alt="Image may contain: 5 person, car, motorcycle"> <br>Image may contain: 5 person, car, motorcycle | <img src="tests/images/london.jpg" width="300" alt="Image may contain: 1 person, car, bus, truck, traffic light"> <br>Image may contain: 1 person, car, bus, truck, traffic light | | <img src="tests/images/home.jpg" width="300" alt="Image may contain: chair, couch"> <br>Image may contain: chair, couch | <img src="tests/images/pizza.jpg" width="300" alt="Image may contain: pizza, dining table"> <br>Image may contain: pizza, dining table | <img src="tests/images/dog.jpg" width="300" alt="Image may contain: dog"> <br>Image may contain: dog | <img src="tests/images/birds.jpg" width="300" alt="Image may contain: bird"> <br>Image may contain: bird |

Installation

Requires: PHP 7.1.3+, OpenCV, PHP OpenCV
Model used: SSDLite COCO v2

Pull the package via composer.

$ composer require ankitpokhrel/alt

Usage

$alt = new \Alt\Alt('/path/to/image.ext');

echo $alt->alt(); // Image may contain: 6 person, cup, laptop

$alt->setImage('/path/to/image.ext')->alt(); // Image may contain: car, motorcycle

Threshold

The classification threshold is set to 30 by default. You can adjust it as your need.

$alt->setThreshold(25);

Prefix

By default the alt is prefixed with Image may contain: . You can change this as below:

$alt->setPrefix('Image has: ');

Countable

If you want to display the count of an object, you can do so by setting countable array. person is countable by default.

$alt->setImage('/path/to/image.ext')->alt(); // Image may contain: 5 person, dog, cup

// Adding dog as countable
$alt->setCountable(['person', 'dog'])->alt(); // Image may contain: 5 person, 2 dog, cup

Default text

Default text is used if the model is not able to predict any objects within a given threshold. Default default text is No photo description available..

$alt->setDefaultText('Some scenery.');
View on GitHub
GitHub Stars82
CategoryDevelopment
Updated5mo ago
Forks8

Languages

PHP

Security Score

97/100

Audited on Oct 27, 2025

No findings