- -
+ + +
+
+ Dummy. + +
+
+
+ +
+ +
+ + -

This document contains a few working demos, together with some light documentation to help get you started using Dummy. It also makes a suitable test page. If you can get it to operate without error then you're ready to start using it in your own project.

-

If you're unclear as to why you'd want to do this in the first place, then head over to the project page, or check out the README.md file included with this download.

+

Fill PHP templates with realistic placeholder content, vary the length of an article, or show an image only some of the time. Reload the page to see how your layout handles a different combination.

+

Install with Composer, use it in Laravel and Blade, or copy the folder into a plain PHP project. The instructions and working examples are all here.

+ +

This is a generated snapshot of the PHP demo. Run Dummy locally to get fresh random content on every request.

+
-

Getting Started

+

Getting Started

-

Basic Requirements

-

You'll need a development environment running Apache and PHP compiled with support for GD. Such an environment is provided out-of-the-box by Mac OS X. Alternatively, there are many MAMP and WAMP binaries available to both Mac and Windows users respectively. These are easy to install and configure and a good way to get started if you're on unfamiliar ground.

+

Requirements

+

Use PHP 8.3 or newer with the GD extension enabled. Composer 2 is needed for package installation. The Laravel integration supports Laravel 12 and 13. Dummy needs no database, Docker setup, or native PHP session.

+

To run the demo locally, use the following command from the Dummy directory, then open localhost:8000/demo.php.

+
-

Setup

+

Install with Composer

+

From your application directory, install Dummy as a development dependency. Composer loads dummy(), dumb_luck(), and dumb_question() automatically.

+ +

Next, follow the Laravel setup or the standalone Composer setup below.

+
+ +
+

Laravel & Blade

+

After installing with Composer, run this command from your Laravel application's root directory:

+ +

Laravel discovers Dummy's service provider automatically. The command publishes images, text pools, and ad templates to public/vendor/dummy/assets. Generated crops go into public/vendor/dummy/cache, which PHP creates automatically. The web server needs permission to create and write to that cache directory.

+

Create resources/views/dummy-demo.blade.php and use the helpers directly in the view:

+@php(dummy('text@words:5-9,title')) + +@if (dumb_luck('50%')) + Example image +@endif + +
    +@while (dumb_luck('3-8')) +
  • @php(dummy('text@headline'))
  • +@endwhile +
+CODE, 'Blade'); ?> +

dummy() prints its result. Use @php(...) for it rather than Blade's escaped {{ ... }} output. The 50% condition shows the image about half the time, and the loop produces between three and eight items.

+

Add a route to routes/web.php:

+ +

Start Laravel with your application's normal development command, or run php artisan serve. Open localhost:8000/dummy-demo when using the default local port. Laravel serves the published assets and cached crops from its public directory.

+
+ +
+

Composer in a standalone PHP project

+

After the Composer installation above, put Dummy's assets under your public web root. For a project with a public directory, run:

+ +

Create public/demo.php with the following contents. The three paths connect Dummy to the assets and cache in your public directory:

+ +

+

+Example image +CODE); ?> +

Make sure PHP can create public/dummy/cache, or create it yourself and give the web server write access. Start the server from your application directory and open localhost:8000/demo.php:

+ +

If your project serves files from another directory, adjust the include path and asset locations to match that web root. Generated lorem ipsum works without copying assets; named text pools, images, and ads need the published files.

+
+ +
+

Plain PHP without Composer

    -
  1. Move the main /dummy folder to the root level of your web project, and make sure any .html documents in which you plan to use Dummy are renamed with a .php extension (or enable the .htaccess file in dummy/extras to continue with a .html file extension).

  2. - -
  3. Make sure that any document in which you want to use Dummy has the following code on the opening line.

    -
    -
    -        <? require_once("dummy/dummy.php") ?>
    -      
    -
    -
  4. -
  5. Finally, make the cache folder located at /dummy/cache writable by your web server. If you see an image immediately below this block of text, it's working. A new image should appear every time you reload the page.

  6. +
  7. Copy the entire dummy directory into your public web root. Keep dummy.php, Runtime.php, Lorem.php, and the assets directory together.
  8. +
  9. Create a PHP template in that web root and include Dummy before calling its helpers:
- -
- " width="500" alt="A test image..." /> + + +

+

+ + + Example image + +CODE); ?> +

Make dummy/cache writable by PHP. Dummy creates the directory if its parent is writable. Use php -S localhost:8000 from that web root, or your usual PHP development server, and open the template in your browser.

+

The image below demonstrates image cropping and caching. It uses a larger source image so it stays sharp on high-density displays.

+
+ A randomly selected demo photograph

$filename exists and seems to be writable."; - } elseif (file_exists($filename)) { - echo "$filename exists but it isn't writable by your web server. Please make it writable."; + $cachePath = $GLOBALS['dummy_cache_path']; + if (is_dir($cachePath) && is_writable($cachePath)) { + echo 'Success. Images are rendering and the cache directory is writable.'; } else { - echo "$filename does not seem to exist. Create it and make sure it is writable by your web server."; + echo 'PHP needs write access to the configured image cache directory.'; } ?>

-
+
-

Troubleshooting

-

If things are not working for you here are the first things to check...

-
    -
  • Double check that the path to /dummy/dummy.php in the top of your document is valid. This is the machine path (not the web path), so you might need to change it if you're using Dummy in a subfolder.

  • -
  • Make sure the cache folder located at /dummy/cache is writable by your web server.

  • -
  • If for some reason you're not using a virtual host, or you can't include /dummy on the root of your project, check the very first line of /dummy/dummy.php and make sure the path is valid. This sets the web path to images generated by Dummy.

  • -
+

Paths, cache & image settings

+

In Laravel, publish the configuration if you need different asset paths or a URL prefix:

+ +

Edit config/dummy.php. These are the defaults:

+ '/vendor/dummy', + 'assets_path' => public_path('vendor/dummy/assets'), + 'cache_path' => public_path('vendor/dummy/cache'), +]; +CODE, 'PHP', 'php'); ?> +

Set custom paths before publishing assets. The URL must serve the matching asset and cache directories. If configuration is cached, run php artisan config:cache after changing it.

+

Outside Laravel, set $dummy_path, $dummy_assets_path, and $dummy_cache_path before rendering, as in the Composer example above. The include path is a filesystem path; $dummy_path is the public URL prefix. Inside a function, set these through $GLOBALS.

+

Optional image constants such as JPEG_QUALITY (default 90), MAX_WIDTH_PX (default 2048), and MAX_HEIGHT_PX (default 1536) must be set before loading Dummy. In Laravel or a Composer project, that means before loading vendor/autoload.php. Use a fresh cache directory when changing JPEG quality so existing crops are not reused.

-

Tips

+

Troubleshooting

    -
  • The use of a virtual host for your web project is not only a solid best practice, it also makes Dummy a zero-config affair. For Mac users, Patrick Gibson's virtualhost.sh script for creating and managing virtual hosts is an excellent place to start. But there are lots of command line and GUI based alternatives across all platforms.

  • -
  • If you prefer to keep your document file extensions as .html, enable the file located at /dummy/extras/optional.htaccess file by removing the "optional" prefix and moving it to the root of your web project. Doing so will ask Apache to parse HTML documents as if they were PHP.

  • +
  • If PHP cannot find Dummy, check the filesystem path in require_once. Use __DIR__ so it does not depend on the current working directory.
  • +
  • If images fail to load, confirm that the configured public URL points to the assets and cache directories, and that PHP can write to the cache.
  • +
  • If GD is missing, enable the GD extension for the PHP runtime serving the page. Your terminal and web server can use different PHP configurations.
  • +
  • Use standard <?php ... ?> tags. Old templates using <? ... ?> need PHP's short_open_tag setting; new examples do not.
+

Text pools and custom ad templates can contain executable PHP. Use trusted local files. Keep Dummy as a development dependency for prototyping and QA.

@@ -92,19 +216,18 @@

The ability to select, manipulate, and insert different assets into your front-end project is a key feature of Dummy. All of the assets available to Dummy live in a folder located at dummy/assets/. It's a good idea to poke around in here and see how things are structured. The simple syntax used to request different assets relates very much to the structure of this directory.

-

Dummy Text

+

Dummy Text

Dummy makes it easy to insert random strings of Lorem Ipsum that correspond to commonly needed lengths and formats. For example, the following snippet of code will produce a random string of Lorem Ipsum approximately the length of a headline.

-
-    <? dummy("text@headline") ?>
-  
+
PHP + HTML
+
<?php dummy("text@headline") ?>

The exact result will be different every time you reload your document, but it should look something like this...

-

+

The following table is a catalog of Dummy's default assets, the snippet of code used to insert the asset, and a sample of actual output.

@@ -121,63 +244,63 @@ Headline - <? dummy("text@headline") ?> - + <?php dummy("text@headline") ?> + Teaser - <? dummy("text@teaser") ?> - + <?php dummy("text@teaser") ?> + Short Teaser - <? dummy("text@short-teaser") ?> - + <?php dummy("text@short-teaser") ?> + Long Teaser - <? dummy("text@long-teaser") ?> - + <?php dummy("text@long-teaser") ?> + Item - <? dummy("text@item") ?> - + <?php dummy("text@item") ?> + Date - <? dummy("text@date") ?> - + <?php dummy("text@date") ?> + Time - <? dummy("text@time") ?> - + <?php dummy("text@time") ?> + Time ago (relative) - <? dummy("text@time-ago") ?> - + <?php dummy("text@time-ago") ?> + Author - <? dummy("text@author") ?> - + <?php dummy("text@author") ?> + Username - <? dummy("text@username") ?> - + <?php dummy("text@username") ?> + City - <? dummy("text@city") ?> - + <?php dummy("text@city") ?> + Paragraph - <? dummy("text@paragraph") ?> - + <?php dummy("text@paragraph") ?> + @@ -186,37 +309,80 @@
-

Dummy Images

+

Lorem ipsum at any length

+

Keep using named text pools for headlines and other curated content, or generate fresh lorem ipsum by specifying a count. Use a single number for an exact length, or a range for a different length on each call.

+ +
+
PHP + HTML
+
<?php dummy("text@words:50") ?>
+<?php dummy("text@words:30-60") ?>
+<?php dummy("text@words:5-9,title") ?>
+<?php dummy("text@sentences:2-4") ?>
+<?php dummy("text@paragraphs:2-3") ?>
+
+ +
+ + + + + + + + + +
LengthDummy CodeLive output
Exactly 50 words<?php dummy("text@words:50") ?>
30–60 words<?php dummy("text@words:30-60") ?>
5–9 words, title case<?php dummy("text@words:5-9,title") ?>
2–4 sentences<?php dummy("text@sentences:2-4") ?>
2–3 paragraphs<?php dummy("text@paragraphs:2-3") ?>
+

Output is plain text. Add ,title to capitalize every word; omit it for normal sentence casing. Paragraphs are separated by blank lines; use your own markup or CSS to display those breaks. Zero returns no text. Ranges include both endpoints. Limits per call: 10,000 words, 1,000 sentences, or 100 paragraphs. No extra packages or asset publishing needed.

+
+
+ +
+

Dummy Images

Dummy makes it easy to crop and size placeholder images on the fly. It ships with a starter pack of high-quality, newsworthy, Creative Commons licensed images, but like other assets it's easy to edit or expand these according to the needs of your project.

The syntax for requesting an image is flexible. In a very basic example, you request an image with specific dimensions...

-
-    <img src="<? dummy("image@480x320") ?>" />
-  
+
PHP + HTML
+
<img src="<?php dummy("image@480x320") ?>" />

...and the following is returned:

- " /> + " width="480" height="320" alt="A 480 by 320 pixel crop" /> +

This example returns exactly 480×320 image pixels. At 480 CSS pixels wide, it is a 1× image; high-density screens benefit from a larger crop, as shown below.

You can specify exact pixel dimensions or just an aspect ratio. You can also combine these parameters. For example, you can choose to specify just the width together with an aspect ratio. Dummy will return the path to an image that conforms to both requirements.

-
-    <img src="<? dummy("image@640x,16:9") ?>" />
-  
+
PHP + HTML
+
<img src="<?php dummy("image@640x,16:9") ?>" />

Returns...

- " /> -

Note: Dummy returns a URL path to an image, not the HTML needed to embed it.

+ " width="640" height="360" alt="A crop with a 16 to 9 aspect ratio" /> +

Use the returned image URL in your <img> element's src attribute.

+

Sharp images on high-density screens

+

Image dimensions are real pixels, not CSS display sizes. For a photo displayed at 640 pixels wide, request a larger crop and set its display width separately. The example below requests 1920×1080 pixels and displays them at 640×360, giving the browser three image pixels per CSS pixel.

+" + width="640" + height="360" + alt="A high-resolution demo photograph" +> +CODE); ?> +
+ A high-resolution demo photograph +

The bundled image/retina folder contains 2048×1536 source photos. Some older landscape photos are only 1024–1150 pixels wide. A larger request cannot restore detail missing from the original.

+
+

JPEG crops are encoded at quality 90 by default. That adds some compression, but reducing the pixel dimensions is the main reason the earlier demo looked soft on a high-density screen. Supply a sufficiently large source and request enough pixels for the intended display size. Aspect-ratio-only commands such as image@16:9 crop at the source's available resolution.

+

The following table provides some clues as to how you can structure your image requests.

@@ -231,64 +397,63 @@ 100px square Classic. Square. - <? dummy("image@100x100") ?> - "> + <?php dummy("image@100x100") ?> + 100px square (Part II) A rather pointless way of generating the same result as above. Proving a point here. - <? dummy("image@100x,1:1") ?> - "> + <?php dummy("image@100x,1:1") ?> + 16:9 With a height of 200px. Pixel dimensions and aspect ratios must be separated with a comma. - <? dummy("image@16:9,x200") ?> - "> + <?php dummy("image@16:9,x200") ?> + 16:9 (Part II) Same as above. It doesn't matter which order you specify ratio or pixel dimensions. - <? dummy("image@x200,16:9") ?> - "> + <?php dummy("image@x200,16:9") ?> + - 3:2 The Photographer's aspect! We'll ask for assets from a specific subdirectory of ‘dummy/assets/images/’ here to improve the odds of getting a suitable image. - <? dummy("image/landscape@3:2") ?> - "> + 3:2 The Photographer's aspect! We'll ask for assets from a specific subdirectory of ‘dummy/assets/image/’ here to improve the odds of getting a suitable image. + <?php dummy("image/landscape@3:2") ?> + - !Avatar Subdirectories of ‘dummy/assets/images/’ that begin with a ‘!’ are exempted from normal random (and recursive) selection. You have to target them specifically. This is good. - <? dummy("image/!avatar@150x150") ?> - "> + !Avatar Subdirectories of ‘dummy/assets/image/’ that begin with a ‘!’ are exempted from normal random (and recursive) selection. You have to target them specifically. This is good. + <?php dummy("image/!avatar@150x150") ?> +

Note: When specifying dimensions, either as an exact pixel measurement or as an aspect ratio, describe the width first and height second (Width x Height).

-

The basic model for how Dummy selects image assets is semi-random and recursive. It begins looking for assets on the root level of "assets/images" and drills down, only ignoring sub-folders with names that begin with a ‘!’. Dummy also works in the background to track which image was most recently selected, in order to minimize the odds of inserting the same image in succession or in close proximity.

+

The basic model for how Dummy selects image assets is semi-random and recursive. It begins looking for assets on the root level of "assets/image" and drills down, only ignoring sub-folders with names that begin with a ‘!’. Dummy also works in the background to track which image was most recently selected, in order to minimize the odds of inserting the same image in succession or in close proximity.

-

Dummy Ads

-

Inside of /dummy/assets/ads you'll find a host of folders representing many of the popular formats as defined by the IAB. The dummy code used to request and insert an ad follows the now familiar model.

+

Dummy Ads

+

Inside of /dummy/assets/ad you'll find a host of folders representing many of the popular formats as defined by the IAB. The dummy code used to request and insert an ad follows the now familiar model.

-
-    <? dummy("ad@120x90") ?>
-  
+
PHP + HTML
+
<?php dummy("ad@120x90") ?>

Returns...

- +

Note that a request for an ad returns a pre-formatted block of embed code containing an ad, as opposed to just the URL path to the ad (as is done with images). The reason for this is that we often need blocks of repetitious, ancillary markup to surround ad placements, as is the case with regard to advertising in the Adobe® Flash® format.

-

The default embed code for both standards compliant image based ads and ads in the Flash format can be found on the root level of /dummy/assets/ads in the form of two files — image.embed.php and flash.embed.php respectively. You can override the use of these defaults by placing an edited copy of one or both of these files in the folder of the format you wish to override.

+

The default embed code for both standards compliant image based ads and ads in the Flash format can be found on the root level of /dummy/assets/ad in the form of two files — image.embed.php and flash.embed.php respectively. You can override the use of these defaults by placing an edited copy of one or both of these files in the folder of the format you wish to override.

The folders containing different formats are also used to specify their dimensions (WxH). Dummy parses these folder names and interprets them as variables, which in turn can be used to set the width and height values of ads as they are parsed into the embed code. If you don't feel it necessary to pass these values to your embed code, you're free to add new formats in folders and name them however you like — just remember to create a custom embed for these formats.

-

You may find it useful to enable or disable the insertion of Flash format ads under different testing scenarios. There is a global preference toggle in the top of dummy.php for controlling this. The default is disabled.

+

You may find it useful to enable or disable the insertion of Flash format ads under different testing scenarios. Set $flash_ads = true before rendering to include legacy Flash ads. The default is disabled, and current browsers do not support Flash.

@@ -301,47 +466,44 @@

A basic building block of Dummy driven layouts, dumb_luck can be used to influence the probability that something will happen when the document is rendered. This helps answer the age old question, “What does this layout look like with or without X ?”, where X could be an image, a special announcement, or a block of JavaScript that triggers some other chain of events.

-
-    <? if (dumb_luck("50%")): ?>
-      There is a 50/50 chance of this happening.
-    <? endif ?>
-  
+
PHP + HTML
+
<?php if (dumb_luck("50%")): ?>
+  There is a 50/50 chance of this happening.
+<?php endif ?>

Jazz up your dumb_luck logic with fallback or alternative outcomes using standard PHP if/else statement structure.

-
-    <? if (dumb_luck("95%")): ?>
-      Pretty damn likely to happen.
-    <? else: ?>
-      This is a lot less likely.
-    <? endif ?>
-  
+
PHP + HTML
+
<?php if (dumb_luck("95%")): ?>
+  Pretty damn likely to happen.
+<?php else: ?>
+  This is a lot less likely.
+<?php endif ?>

You can also nest dumb_luck logic as needed, to test and explore more complex outcomes.

-
-    <? if (dumb_luck("50%")): ?>
-      <? if (dumb_luck("50%")): ?>
-        Heads
-      <? else: ?>
-        Tails
-      <? endif ?>
-    <? else: ?>
-      <? if (dumb_luck("33%")): ?>
-        Rock
-      <? elseif (dumb_luck("33%")): ?>
-        Paper
-      <? else: ?>
-        Scissors
-      <? endif ?>
-    <? endif ?>
-  
- -

For the record... HeadsTailsRockPaperScissors!

+
PHP + HTML
+
<?php if (dumb_luck("50%")): ?>
+  <?php if (dumb_luck("50%")): ?>
+    Heads
+  <?php else: ?>
+    Tails
+  <?php endif ?>
+<?php else: ?>
+  <?php if (dumb_luck("33%")): ?>
+    Rock
+  <?php elseif (dumb_luck("33%")): ?>
+    Paper
+  <?php else: ?>
+    Scissors
+  <?php endif ?>
+<?php endif ?>
+ +

For the record... HeadsTailsRockPaperScissors!

@@ -349,9 +511,9 @@

Creating Loop Ranges

- - " width="35" height="35" alt="A thumbnail..." /> - + + " width="35" height="35" alt="A thumbnail..." /> +

Dumb Luck's loop range takes whatever content you place inside of it and loops it within a range of two numbers that you specify. Inside of the loop range above, a single request for a 35x35 pixel thumbnail.

@@ -360,23 +522,21 @@

The thumbnail will be rendered no less than 50 times, and up to 100. The Dummy code used to achieve this is compact and human readable:

-
-  <? while (dumb_luck("50-100")): ?>
-    <? dummy("image@35x35") ?>
-  <? endwhile ?>
-  
+
PHP + HTML
+
<?php while (dumb_luck("50-100")): ?>
+  <?php dummy("image@35x35") ?>
+<?php endwhile ?>

Loop ranges are built on the same dumb_luck function used to control probability, only instead of passing in a % value we pass it a range of two numbers separated by a hyphen. These two values define the minimum and maximum number of times the loop should continue. In the example below, we ask for between 5 and 10 instances of a list item containing a headline.

-
-  
    - <? while (dumb_luck("5-10")): ?> -
  • <? dummy("text@headline") ?>
  • - <? endwhile ?> -
-
+
PHP + HTML
+
<ul>
+<?php while (dumb_luck("5-10")): ?>
+  <li><?php dummy("text@headline") ?></li>
+<?php endwhile ?>
+</ul>

Note that the PHP syntax used with dumb_luck requires “WHILE” in association with loop ranges.

@@ -384,9 +544,9 @@
    - -
  • - + +
  • +
@@ -397,42 +557,40 @@

Taking the same list used in the previous example, imagine we needed to see how it would look with some of the items linked some of the time. To achieve this we'll nest some probability logic inside of our loop range.

-
-    
    - <? while (dumb_luck("5-10")): ?> - <? if (dumb_luck("50%")): ?> -
  • <? dummy("text@headline") ?>
  • - <? else: ?> -
  • <? dummy("text@headline") ?>
  • - <? endif ?> - <? endwhile ?> -
-
+
PHP + HTML
+
<ul>
+<?php while (dumb_luck("5-10")): ?>
+  <?php if (dumb_luck("50%")): ?>
+    <li><a href="#"><?php dummy("text@headline") ?></a></li>
+  <?php else: ?>
+    <li><?php dummy("text@headline") ?></li>
+  <?php endif ?>
+<?php endwhile ?>
+</ul>

Though the exact number will change every time you reload the page, roughly half of the items in the following list will be wrapped in a link. It's a very basic example, but one that uses all the core features of Dummy.

-
+

When used together, asset generation, probability, and loop range logic can create highly variable layouts with very little effort in code. This makes it possible to quickly test how the change of an item, attribute or parameter in one place propagates on a range of different scales. It can provide new insights on the performance or design efficacy of your work at the earliest stages of a project, and every time you reload the page.

-
-    

<? dummy("text@headline") ?>

- <? if (dumb_luck("25%")): ?> -

<? dummy("text@long-teaser") ?>

- <? endif ?> -

By <? dummy("text@author") ?> | Published <? dummy("text@date") ?>

- <? while (dumb_luck("3-8")): ?> -

<? dummy("text@paragraph") ?>

- <? endwhile ?> - <? if (dumb_luck("75%")): ?> -

Related Story: <? dummy("text@headline") ?>

- <? endif ?> -
+
PHP + HTML
+
<h1><?php dummy("text@headline") ?></h1>
+<?php if (dumb_luck("25%")): ?>
+  <p class="intro"><?php dummy("text@long-teaser") ?></p>
+<?php endif ?>
+<p>By <?php dummy("text@author") ?> | Published <?php dummy("text@date") ?></p>
+<?php while (dumb_luck("3-8")): ?>
+  <p><?php dummy("text@paragraph") ?></p>
+<?php endwhile ?>
+<?php if (dumb_luck("75%")): ?>
+  <p><b>Related Story:</b> <a href="#"><?php dummy("text@headline") ?></a></p>
+<?php endif ?>

An example of a simple article 3 to 8 paragraphs in length, with optionally appearing intro text and related story elements.

@@ -440,23 +598,20 @@
-

More to come

-

There are a few unfinished features in Dummy that remain too fluid to document, namely the dumb_question function for reading and reacting to loop position, URL variables, and URL segments. More info to come on those when they're done.

+

Loop positions and request queries

+

Inside a loop, dumb_question("order:first"), dumb_question("order:last"), and dumb_question("order:inner") test the current position. dumb_luck("") prints the one-based item number.

+

dumb_question("url:mode=compact") tests a query parameter, and dumb_question("segment:1=news") tests the first URL path segment. Laravel uses its current request automatically. See paths, cache and image settings for configuration.

In the meantime, follow the project on GitHub. Your ideas and contributions toward improving the code are welcome.

-
+
-

This page documents Dummy v. 1.0 — Ideas, questions, reprimands? @kerns.

+

Dummy for rapid prototyping and QA — GitHub · Image credits

- - - - - +
+