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. [Image &amp; Media](/categories/media)
4. /
5. mitogh/random-image

ActiveLibrary[Image &amp; Media](/categories/media)

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

Retrive random images from the library of attachments.

1.0.1(10y ago)130MITPHPPHP &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 4w 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

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

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

3831d 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

[rosell-dk/webp-convert

Convert JPEG &amp; PNG to WebP with PHP

6058.7M59](/packages/rosell-dk-webp-convert)[humanmade/gaussholder

Fast and lightweight image previews for WordPress

196120.0k](/packages/humanmade-gaussholder)[mindkomm/timmy

Advanced image manipulation for Timber.

17737.1k](/packages/mindkomm-timmy)[wp-media/imagify-plugin

Image optimization plugin for WordPress by WP Media.

8065.3k](/packages/wp-media-imagify-plugin)[mmo/faker-images

Different images provider for Faker

56403.1k7](/packages/mmo-faker-images)[spatie/pixelmatch-php

Compare images using PHP

5896.4k16](/packages/spatie-pixelmatch-php)

PHPackages © 2026

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