{"id":16050165,"url":"https://github.com/mitogh/random-image","last_synced_at":"2026-06-17T06:32:12.848Z","repository":{"id":17000317,"uuid":"19763478","full_name":"mitogh/Random-Image","owner":"mitogh","description":":camera: Wordpress - Retrieve random images from the attachments library..","archived":false,"fork":false,"pushed_at":"2016-01-02T19:01:20.000Z","size":45,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-02T15:49:56.439Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mitogh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-14T02:30:07.000Z","updated_at":"2016-06-04T04:56:45.000Z","dependencies_parsed_at":"2022-08-27T00:02:00.348Z","dependency_job_id":null,"html_url":"https://github.com/mitogh/Random-Image","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitogh%2FRandom-Image","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitogh%2FRandom-Image/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitogh%2FRandom-Image/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitogh%2FRandom-Image/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mitogh","download_url":"https://codeload.github.com/mitogh/Random-Image/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240122574,"owners_count":19751142,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-09T00:42:48.305Z","updated_at":"2026-05-17T11:30:17.363Z","avatar_url":"https://github.com/mitogh.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Random Image [![Build Status](https://travis-ci.org/mitogh/Random-Image.svg)](https://travis-ci.org/mitogh/Random-Image)\n===================\n\n\u003e Easily random image generation from the library of attachments or from\n a post, page or custom post type ID.  \n\n## Description\n\nWhith this small utility you can easy and fast access to the group of\nrandom images from the library or from a post using the ID of the post,\nyou can access to the IDs of this images or the `src` of each image by\nsize.  \n\n## Requirements.  \n\n- WordPress\n- PHP 5.3 \u003e=\n\n## Installation  \n\nYou can add this library into your theme or plugin by using composer,\nand adding this library as a dependency, just by running: \n\n```php\ncomposer require mitogh/random-image\n```\n\nAfter that make sure you include the library using the autoload file\nfrom composer: \n\n```php\ninclude './vendor/autoload.php';\n```\n\nOr by using directly the file.  \n\n```php\ninclude 'vendor/mitogh/random-image/src/RandomImage.php';\n```\n\n## Usage\n\nIn order to access to the public functions you need to create an\ninstance of `RandomImage` class as follows: \n\n```php\n$randomImage = new mitogh\\RandomImage();\n```\n\nOptionally you can pass an array of arguments to update some arguments\nbefore to retrieve the random images, the arguments are: \n\n- count: you can specify the number of images to be searched, default is 1.\n- parent_ID: you can specify the ID of the page, post, post type from\n  where to search the images if you don't want to search on the entiry\nlibrary of attachments, default is null and searches the entiry library.  \n\nSo for example if you want to have 3 random images from the page with\nthe ID: 2.  \n\n```php\n$args = array(\n  'count' =\u003e 3,\n  'parent_ID' =\u003e 2,\n);\n$randomImage = new mitogh\\RandomImage( $args );\n```\n\n**Filters**\n\nAditionally you can update the default mime of the searched files, using\nthe filter `mitogh_rand_image_mime_type`, by default the mime types are: \n\n```php\nimage/jpeg\nimage/gif\nimage/png\nimage/bmp\nimage/tiff\n```\n\nYou can update this by using the filter and returning an array with the\ntype, for example to search only gif images:  \n\n```php\nadd_filter( 'mitogh_rand_image_mime_type', function( $default_types ) ) {\n    return array(\n\t\t'image/gif',\n    );\n});\n```\n\n## Public methods\n\nYou have access to 2 methods with the instance to `RandomImage`, the\nmethods are:   \n\n**get_ids**\n\nWith this method you can access to the ID of each image, and by having\nthe ID of the image you can use another functions to operate over each\nimage as follows: \n\n```php\n$randomImage = new mitogh\\RandomImage();\n$images_id = $randomImage-\u003eget_ids();\n// Now images_id has an array with the id of each image, and you can use \n// each id to operate over each image.\n```\n\n**get_srcs**\n\nThis method will return an array with the src attribute of each image so\nyou can use each value in a `\u003cimg\u003e` tag. Aditionally you can specify the\nsize of the images (all of them) before returned.\n\n```php\n$randomImage = new mitogh\\RandomImage();\n$images_src = $randomImage-\u003eget_srcs( 'full' );\n// Now images_src has an array with the src value of the images with the\n// full size.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitogh%2Frandom-image","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmitogh%2Frandom-image","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitogh%2Frandom-image/lists"}