Objective ways to print images in 5.7

This is a community-contributed tutorial. This tutorial is over a year old and may not apply to your version of Concrete CMS.
May 20, 2015

First, get page's image attribute value like:

$img = $page->getAttribute('example_image_attribute_handle');
if ($img) {
    // do something
}

Case 1: Print responsive image (if your theme supports responsive image)

$tag = Core::make('html/image', array($img))->getTag();
echo $tag;

Case 2: Add some attributes to the image

$tag = Core::make('html/image', array($img))->getTag();
$tag->alt('alt test');
$tag->title('title test');
$tag->addClass('example class');
echo $tag;

Case 3: Remove some attributes from the image

$tag = Core::make('html/image', array($img))->getTag();
$tag->width = null;
$tag->height = null;
echo $tag;

Case 4: Do not use responsive image (picture element)

$tag = Core::make('html/image', array($img, false))->getTag();
echo $tag;

Case 5: Get thumbnail src of the image

$src = $img->getThumbnailURL('small');
echo \HtmlObject\Image::create($src)->alt('small size image');

Note: Loader::helper('image') is officially deprecated.

Recent Tutorials
How to Automate the Copyright Year
Dec 27, 2024

Learn how to keep your website's copyright year updated automatically in Concrete CMS.

How to change the path of a group of pages
Dec 23, 2024
By myq.

Change the canonical path without breaking things

Bi-directional Express associations
Dec 18, 2024
By myq.

Set up associations between Express entries in both directions

Display Express Data Across Multiple Sites
Dec 17, 2024
By myq.

A guide to configuring Express entities and the Express Entry List block to ensure proper data display across multiple sites.

Customize locale icons
Oct 29, 2024
By myq.

How to customize locale (language region) flags

Concrete CMS Caching Guide
Oct 16, 2024

An overview of types of caching in Concrete and considerations when using them.

Improvements?

Let us know by posting here.