Add support for ".png" buttons

Fixes #48
This commit is contained in:
Dmitriy Simushev 2014-08-04 15:33:19 +00:00
parent ef5c919803
commit a99a839998
4 changed files with 34 additions and 17 deletions

View File

@ -101,8 +101,12 @@ class ButtonCodeController extends AbstractController
: $image_locales[0]; : $image_locales[0];
} }
$file = MIBEW_FS_ROOT . '/locales/${lang}/button/${image}_on.gif'; $file = MIBEW_FS_ROOT . '/locales/${lang}/button/${image}_on.png';
$size = get_gifimage_size($file); if (!is_readable($file)) {
// Fallback to .gif image
$file = MIBEW_FS_ROOT . '/locales/${lang}/button/${image}_on.gif';
}
$size = get_image_size($file);
$image_link_args = array( $image_link_args = array(
'i' => $image, 'i' => $image,

View File

@ -80,7 +80,13 @@ class ButtonController extends AbstractController
// Get image file content // Get image file content
$image_postfix = has_online_operators($group_id) ? "on" : "off"; $image_postfix = has_online_operators($group_id) ? "on" : "off";
$file_name = "locales/${lang}/button/${image}_${image_postfix}.gif"; $file_name = "locales/${lang}/button/${image}_${image_postfix}.png";
$content_type = 'image/png';
if (!is_readable($file_name)) {
// Fall back to .gif image
$file_name = "locales/${lang}/button/${image}_${image_postfix}.gif";
$content_type = 'image/gif';
}
$fh = fopen($file_name, 'rb'); $fh = fopen($file_name, 'rb');
if ($fh) { if ($fh) {
@ -91,7 +97,7 @@ class ButtonController extends AbstractController
$response = new Response($content, 200); $response = new Response($content, 200);
// Set correct content info // Set correct content info
$response->headers->set('Content-Type', 'image/gif'); $response->headers->set('Content-Type', $content_type);
$response->headers->set('Content-Length', $file_size); $response->headers->set('Content-Length', $file_size);
} else { } else {
$response = new Response('Not found', 404); $response = new Response('Not found', 404);

View File

@ -15,19 +15,26 @@
* limitations under the License. * limitations under the License.
*/ */
function get_gifimage_size($filename) function get_image_size($filename)
{ {
if (function_exists('gd_info')) { $ext = pathinfo($filename, PATHINFO_EXTENSION);
$info = gd_info();
if (isset($info['GIF Read Support']) && $info['GIF Read Support']) {
$img = @imagecreatefromgif($filename);
if ($img) {
$height = imagesy($img);
$width = imagesx($img);
imagedestroy($img);
return array($width, $height); if (function_exists('gd_info') && ($ext == 'gif' || $ext == 'png')) {
} $info = gd_info();
$img = false;
if ($ext == 'gif' && !empty($info['GIF Read Support'])) {
$img = @imagecreatefromgif($filename);
} elseif ($ext == 'png' && !empty($info['PNG Support'])) {
$img = @imagecreatefrompng($filename);
}
if ($img) {
$height = imagesy($img);
$width = imagesx($img);
imagedestroy($img);
return array($width, $height);
} }
} }

View File

@ -190,8 +190,8 @@ function get_image_locales_map($locales_dir)
$images_dir = "$locales_dir/$curr/button"; $images_dir = "$locales_dir/$curr/button";
if ($handle = @opendir($images_dir)) { if ($handle = @opendir($images_dir)) {
while (false !== ($file = readdir($handle))) { while (false !== ($file = readdir($handle))) {
$both_files_exist = preg_match("/^(\w+)_on.gif$/", $file, $matches) $both_files_exist = preg_match("/^(\w+)_on\.(gif|png)$/", $file, $matches)
&& is_file("$images_dir/" . $matches[1] . "_off.gif"); && is_file("$images_dir/" . $matches[1] . "_off." . $matches[2]);
if ($both_files_exist) { if ($both_files_exist) {
$image = $matches[1]; $image = $matches[1];
if (!isset($image_locales[$image])) { if (!isset($image_locales[$image])) {