PHP Classes

Custom Headlines: Render text headlines on the top of images

Recommend this page to a friend!
  Info   View files Example   Screenshots Screenshots   View files View files (13)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 226 This week: 1All time: 8,194 This week: 560Up
Version License PHP version Categories
custom-headlines 1.0GNU General Publi...3.0PHP 5, Graphics, Text processing
Description 

Author

This class can render text headlines on the top of images.

It can take a given image and renders a text inside a given rectangle of the image.

The resulting image is saved to another given file.

The font, text color, transparency level are some of the configurable parameters.

Picture of Luciano Salvino
  Performance   Level  
Name: Luciano Salvino <contact>
Classes: 11 packages by
Country: Argentina Argentina
Age: 51
All time rank: 134516 in Argentina Argentina
Week rank: 411 Up3 in Argentina Argentina Up
Innovation award
Innovation award
Nominee: 9x

Example

<?php

include('CustomHeadlines.php');

// initializing class
$ch = new CustomHeadlines();

// define inverse color of text to false (it will be in black or white depends on predominance of the image background color)
$ch->colorInverse = false;
// define the image path
$image = 'images/example.jpg';
// define the result image path
$imageResult = 'images/example_result1.jpg';
// define the text box background transparency (0:full color/100: 100% transparent)
$alpha = 40;
// define the text of headlines
$headline = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua';
// set the font family (default: arial)
$ch->getFontFile();
// define headlines font size (it could be different if the box size is smaller respect the text)
$ch->setFontSize(18);
// define headlines box size
$areaX = 10;
$areaY = 10;
$areaW = 560;
$areaH = 90;
// generate the image result with headlines box
$ch->Create($image,$headline,$areaX,$areaY,$areaW,$areaH,$alpha,$imageResult);

echo
'<h3>Example 1:</h3>';
echo
'<p><img src="'.$ch->getImage().'"></p>';

$imageResult = 'images/example_result2.jpg';
$areaX = 10;
$areaY = 100;
$areaW = 560;
$areaH = 90;

$ch->Create($image,$headline,$areaX,$areaY,$areaW,$areaH,$alpha,$imageResult);

echo
'<p><img src="'.$ch->getImage().'"></p>';

$imageResult = 'images/example_result3.jpg';
$areaX = 10;
$areaY = 250;
$areaW = 560;
$areaH = 90;

$ch->Create($image,$headline,$areaX,$areaY,$areaW,$areaH,$alpha,$imageResult);

echo
'<p><img src="'.$ch->getImage().'"></p>';

echo
'<h3>Example 2:</h3>';

// headlines will shown on inverse color respect the background box
$ch->colorInverse = true;
$ch->getFontFile();
$ch->setFontSize(22);
$image = 'images/example2.jpg';
$imageResult = 'images/example2_result1.jpg';
$alpha = 50;
$areaX = 10;
$areaY = 10;
$areaW = 450;
$areaH = 120;

$ch->Create($image,$headline,$areaX,$areaY,$areaW,$areaH,$alpha,$imageResult);

echo
'<p><img src="'.$ch->getImage().'"></p>';

$imageResult = 'images/example2_result2.jpg';
$areaX = 10;
$areaY = 80;
$areaW = 450;
$areaH = 120;

$ch->Create($image,$headline,$areaX,$areaY,$areaW,$areaH,$alpha,$imageResult);

echo
'<p><img src="'.$ch->getImage().'"></p>';

$imageResult = 'images/example2_result3.jpg';
$areaX = 10;
$areaY = 250;
$areaW = 450;
$areaH = 120;

$ch->Create($image,$headline,$areaX,$areaY,$areaW,$areaH,$alpha,$imageResult);

echo
'<p><img src="'.$ch->getImage().'"></p>';


Details

CustomHeadlines

CustomHeadlines is a PHP class that add headlines to images with text and background color depending on the image color index of selected area

Usage

// Define parameters

// Image Source

$image = 'images/example.jpg';
// Image result
$imageResult = 'images/example_result1.jpg';
// alpha of the box area
$alpha = 40;
// text of headline
$headline = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua';
// Fontsize
$fontSize = 18;
// Box area position and measures
$areaX = 10;
$areaY = 10;
$areaW = 560;
$areaH = 90;

// Initialize Class
$ch = new CustomHeadlines();

// set font size and family
$ch->getFontFile();
$ch->setFontSize(22);

// You can set the inverse color to set text with de inverse color respect of background (optionl)
$ch->colorInverse = true; // Default: false

// Create image
$ch->Create($image,$headline,$areaX,$areaY,$areaW,$areaH,$alpha,$imageResult);

// Get the image
$imgaeResult = $ch->getImage();

Screenshots  
  • example2_result1.jpg
  • example_result1.jpg
  • example_result2.jpg
  • example_result3.jpg
  Files folder image Files  
File Role Description
Files folder imageimages (8 files)
Accessible without login Plain text file composer.json Data composer
Plain text file CustomHeadlines.php Class class
Accessible without login Plain text file example.php Example example
Accessible without login Plain text file LICENSE Data license
Accessible without login Plain text file README.md Doc. Readme

  Files folder image Files  /  images  
File Role Description
  Accessible without login Image file example.jpg Icon image example
  Accessible without login Image file example2.jpg Icon image example
  Accessible without login Image file example2_result1.jpg Icon image example
  Accessible without login Image file example2_result2.jpg Icon image example
  Accessible without login Image file example2_result3.jpg Icon image example
  Accessible without login Image file example_result1.jpg Icon image example
  Accessible without login Image file example_result2.jpg Icon image example
  Accessible without login Image file example_result3.jpg Icon image example

 Version Control Unique User Downloads Download Rankings  
 76%
Total:226
This week:1
All time:8,194
This week:560Up