Jump to content

Page image


Martijn Geerts
 Share

Recommended Posts

Today needed a simple way to add text to an image. I ended up serving a page with images headers.

So using this image from other pages is:

<img src="<?= $pages->get(1234)->url; ?>"  />

Settings for the template:

- not using a slash at the end

- enable template caching

- be shure you end the page name with .png .gif or .jpg

example code

---

Maybe someone comes in the same situation

  • Like 3
Link to comment
Share on other sites

Martijn, sometimes I need some more headers, if not already set with apache or to override the apaches default.

Maybe you find it useful.

	// collect infos
	$maxAge = (60 * 60 * 24 * 2); // 48 hours
	$imgTimestamp = filemtime($imgFilename);
	$imgExpiration = intval(time() + $maxAge);

	// create headers
	$imgHeaders = array();
	$imgHeaders[] = 'Content-type: image/jpeg';      // or other type
	$imgHeaders[] = 'Content-Length: ' . filesize($imgFilename);
	$imgHeaders[] = 'Date: ' . gmdate('D, d M Y H:i:s',time()) . ' GMT';
	$imgHeaders[] = 'Last-Modified: ' . gmdate('D, d M Y H:i:s',$imgTimestamp) . ' GMT';
	$imgHeaders[] = 'Expires: ' . gmdate('D, d M Y H:i:s', $imgExpiration) . ' GMT';
	$imgHeaders[] = 'pragma: cache';
	$imgHeaders[] = "Cache-Control: max-age={$maxAge}";
	//$imgHeaders[] = "Cache-Control: no-transform, public, s-maxage={$maxAge}, max-age={$maxAge}";  // public|private

	// send header
	foreach($imgHeaders as $imgHeader) header($imgHeader);
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...