From ede5d50d6ee50854102d3e46a5cbf0986038d751 Mon Sep 17 00:00:00 2001 From: Abhimanyu Sharma Date: Tue, 17 Dec 2013 21:27:12 +0530 Subject: [PATCH] Added ability to add attributes to html() method Added ability to add attributes like `id` , `class`, `alt` to html() method Uses Image::open('open.jpg')->html($title = 'some title', $type = 'jpg' , array('class'=>'test pull-right','id'=>'test','alt' => 'name'))); `NULL` can also be provided if don't want any attributes just want to change the image quality --- Image.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Image.php b/Image.php index 5939199..fd98abf 100644 --- a/Image.php +++ b/Image.php @@ -650,9 +650,17 @@ public function __toString() /** * Returning basic html code for this image */ - public function html($title = '', $type = 'jpg', $quality = 80) - { - return ''; + public function html($title = '', $type = 'jpg', $attributes = array(), $quality = 80) + { + $html = array(); + if (!empty($attributes)) { + foreach ((array)$attributes as $key => $value) { + if (is_numeric($key)) $key = $value; + if (!is_null($value)) $key . '="' . $value . '"'; + $html[] = $key . '="' . ($value) . '"'; + } + } + return ''; } /**