PHPackages                             mitogh/random-image - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. mitogh/random-image

ActiveLibrary

mitogh/random-image
===================

Retrive random images from the library of attachments.

1.0.1(10y ago)030MITPHPPHP &gt;=5.5

Since Dec 30Pushed 10y ago1 watchersCompare

[ Source](https://github.com/mitogh/Random-Image)[ Packagist](https://packagist.org/packages/mitogh/random-image)[ Docs](https://github.com/mitogh/Random-Image)[ RSS](/packages/mitogh-random-image/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (3)Versions (4)Used By (0)

Random Image [![Build Status](https://camo.githubusercontent.com/431d094339cb752fa7e69677f7d3b4334aa1f3580622a3d5b7e6fa99c20049ee/68747470733a2f2f7472617669732d63692e6f72672f6d69746f67682f52616e646f6d2d496d6167652e737667)](https://travis-ci.org/mitogh/Random-Image)
=========================================================================================================================================================================================================================================================================

[](#random-image-)

> Easily random image generation from the library of attachments or from a post, page or custom post type ID.

Description
-----------

[](#description)

Whith this small utility you can easy and fast access to the group of random images from the library or from a post using the ID of the post, you can access to the IDs of this images or the `src` of each image by size.

Requirements.
-------------

[](#requirements)

- WordPress
- PHP 5.3 &gt;=

Installation
------------

[](#installation)

You can add this library into your theme or plugin by using composer, and adding this library as a dependency, just by running:

```
composer require mitogh/random-image
```

After that make sure you include the library using the autoload file from composer:

```
include './vendor/autoload.php';
```

Or by using directly the file.

```
include 'vendor/mitogh/random-image/src/RandomImage.php';
```

Usage
-----

[](#usage)

In order to access to the public functions you need to create an instance of `RandomImage` class as follows:

```
$randomImage = new mitogh\RandomImage();
```

Optionally you can pass an array of arguments to update some arguments before to retrieve the random images, the arguments are:

- count: you can specify the number of images to be searched, default is 1.
- parent\_ID: you can specify the ID of the page, post, post type from where to search the images if you don't want to search on the entiry library of attachments, default is null and searches the entiry library.

So for example if you want to have 3 random images from the page with the ID: 2.

```
$args = array(
  'count' => 3,
  'parent_ID' => 2,
);
$randomImage = new mitogh\RandomImage( $args );
```

**Filters**

Aditionally you can update the default mime of the searched files, using the filter `mitogh_rand_image_mime_type`, by default the mime types are:

```
image/jpeg
image/gif
image/png
image/bmp
image/tiff
```

You can update this by using the filter and returning an array with the type, for example to search only gif images:

```
add_filter( 'mitogh_rand_image_mime_type', function( $default_types ) ) {
    return array(
		'image/gif',
    );
});
```

Public methods
--------------

[](#public-methods)

You have access to 2 methods with the instance to `RandomImage`, the methods are:

**get\_ids**

With this method you can access to the ID of each image, and by having the ID of the image you can use another functions to operate over each image as follows:

```
$randomImage = new mitogh\RandomImage();
$images_id = $randomImage->get_ids();
// Now images_id has an array with the id of each image, and you can use
// each id to operate over each image.
```

**get\_srcs**

This method will return an array with the src attribute of each image so you can use each value in a `` tag. Aditionally you can specify the size of the images (all of them) before returned.

```
$randomImage = new mitogh\RandomImage();
$images_src = $randomImage->get_srcs( 'full' );
// Now images_src has an array with the src value of the images with the
// full size.
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~3 days

Total

2

Last Release

3785d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3921289?v=4)[Crisoforo Gaspar Hernández](/maintainers/mitogh)[@mitogh](https://github.com/mitogh)

---

Top Contributors

[![mitogh](https://avatars.githubusercontent.com/u/3921289?v=4)](https://github.com/mitogh "mitogh (46 commits)")

---

Tags

randomwordpressimagesattachments

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/mitogh-random-image/health.svg)

```
[![Health](https://phpackages.com/badges/mitogh-random-image/health.svg)](https://phpackages.com/packages/mitogh-random-image)
```

###  Alternatives

[paragonie/random_compat

PHP 5.x polyfill for random\_bytes() and random\_int() from PHP 7

8.2k655.0M405](/packages/paragonie-random-compat)[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k394.3M1.5k](/packages/nette-utils)[spatie/laravel-medialibrary

Associate files with Eloquent models

6.1k37.7M472](/packages/spatie-laravel-medialibrary)[composer/installers

A multi-framework Composer library installer

1.4k136.0M6.0k](/packages/composer-installers)[phpcompatibility/phpcompatibility-wp

A ruleset for PHP\_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by WordPress.

21830.6M587](/packages/phpcompatibility-phpcompatibility-wp)[php-stubs/wordpress-stubs

WordPress function and class declaration stubs for static analysis.

19013.0M263](/packages/php-stubs-wordpress-stubs)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
