if (CRM_Utils_Array::value('image_1', $layout['data'])) {
$formattedRow['image_1'] = $layout['data']['image_1'];
}
+ if (CRM_Utils_Array::value('width_image_1', $layout['data'])) {
+ $formattedRow['width_image_1'] = $layout['data']['width_image_1'];
+ }
+ if (CRM_Utils_Array::value('height_image_1', $layout['data'])) {
+ $formattedRow['height_image_1'] = $layout['data']['height_image_1'];
+ }
if (CRM_Utils_Array::value('image_2', $layout['data'])) {
$formattedRow['image_2'] = $layout['data']['image_2'];
}
+ if (CRM_Utils_Array::value('width_image_2', $layout['data'])) {
+ $formattedRow['width_image_2'] = $layout['data']['width_image_2'];
+ }
+ if (CRM_Utils_Array::value('height_image_2', $layout['data'])) {
+ $formattedRow['height_image_2'] = $layout['data']['height_image_2'];
+ }
if (CRM_Utils_Array::value('add_barcode', $layout['data'])) {
$formattedRow['barcode'] = array(
$titleWidth = $titleLeftMargin = 0;
if (CRM_Utils_Array::value('image_1', $formattedRow)) {
- $this->printImage($formattedRow['image_1']);
+ $this->printImage($formattedRow['image_1'], NULL, NULL, CRM_Utils_Array::value('width_image_1', $formattedRow),
+ CRM_Utils_Array::value('height_image_1', $formattedRow));
$titleWidth = $titleLeftMargin = $this->lMarginLogo;
}
$titleRightMargin = 0;
if (CRM_Utils_Array::value('image_2', $formattedRow)) {
- $this->printImage($formattedRow['image_2'], $x + 68);
+ $this->printImage($formattedRow['image_2'], $x + 68, NULL, CRM_Utils_Array::value('width_image_2', $formattedRow),
+ CRM_Utils_Array::value('height_image_2', $formattedRow));
$titleRightMargin = 36;
$titleWidth = $this->lMarginLogo;
}
* @return void
* @access public
*/
- function printImage($img, $x = '', $y = '') {
+ function printImage($img, $x = '', $y = '', $w = NULL, $h = NULL) {
if (!$x) {
$x = $this->pdf->GetAbsX();
}
$this->imgRes = 300;
if ($img) {
- $imgsize = getimagesize($img);
- // mm
- $f = $this->imgRes / 25.4;
- $w = $imgsize[0] / $f;
- $h = $imgsize[1] / $f;
+ list($w, $h) = self::getImageProperties($img, $this->imgRes, $w, $h);
$this->pdf->Image($img, $x, $y, $w, $h, '', '', '', FALSE, 72, '', FALSE,
FALSE, $this->debug, FALSE, FALSE, FALSE);
}
$this->pdf->SetXY($x, $y);
}
+ static function getImageProperties($img, $imgRes = 300, $w = NULL, $h = NULL) {
+ $imgsize = getimagesize($img);
+ $f = $imgRes / 25.4;
+ $w = !empty($w) ? $w : $imgsize[0] / $f;
+ $h = !empty($h) ? $h : $imgsize[1] / $f;
+ return array($w, $h);
+ }
+
/**
* function to build badges parameters before actually creating badges.
*
$attributes = array('readonly'=> true);
$this->add('text', 'image_1', ts('Image (top right)'),
$attributes + CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'title'));
+ $this->add('text', 'width_image_1', ts('Width'), array('size' => 6));
+ $this->add('text', 'height_image_1', ts('Height'), array('size' => 6));
+
$this->add('text', 'image_2', ts('Image (top left)'),
$attributes + CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'title'));
+ $this->add('text', 'width_image_2', ts('Width'), array('size' => 6));
+ $this->add('text', 'height_image_2', ts('Height'), array('size' => 6));
$this->add('checkbox', 'is_default', ts('Default?'));
$this->add('checkbox', 'is_active', ts('Enabled?'));
$this->add('checkbox', 'is_reserved', ts('Reserved?'));
+ $this->addRule('width_image_1', ts('Width not valid'), 'positiveInteger');
+ $this->addRule('width_image_2', ts('Width not valid'), 'positiveInteger');
+ $this->addRule('height_image_1', ts('Height not valid'), 'positiveInteger');
+ $this->addRule('height_image_2', ts('Height not valid'), 'positiveInteger');
$this->addFormRule(array('CRM_Badge_Form_Layout', 'formRule'));
$this->addButtons(array(
--- /dev/null
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.4 |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013 |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM. |
+ | |
+ | CiviCRM is free software; you can copy, modify, and distribute it |
+ | under the terms of the GNU Affero General Public License |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
+ | |
+ | CiviCRM is distributed in the hope that it will be useful, but |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
+ | See the GNU Affero General Public License for more details. |
+ | |
+ | You should have received a copy of the GNU Affero General Public |
+ | License and the CiviCRM Licensing Exception along |
+ | with this program; if not, contact CiviCRM LLC |
+ | at info[AT]civicrm[DOT]org. If you have questions about the |
+ | GNU Affero General Public License or the licensing of CiviCRM, |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+*/
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC (c) 2004-2013
+ *
+ */
+
+class CRM_Badge_Page_AJAX {
+ static function getImageProp() {
+ $img = $_GET['img'];
+ list($w, $h) = CRM_Badge_BAO_Badge::getImageProperties($img);
+ echo json_encode(array('width' => $w, 'height' => $h));
+ CRM_Utils_System::civiExit();
+ }
+}
\ No newline at end of file
window.KCFinder = {
callBack: function(url) {
field.val(url);
+ // calculate the image default width, height
+ // and assign to respective fields
+ var ajaxUrl = CRM.url('civicrm/ajax/rest', 'className=CRM_Badge_Page_AJAX&fnName=getImageProp&json=1&img=' + url);
+ $.ajax({
+ url: ajaxUrl,
+ async: false,
+ global: false,
+ dataType: "json",
+ success: function ( response ) {
+ var widthId = 'width_' + field.attr('id');
+ var heightId = 'height_' + field.attr('id');
+ $('#' + widthId).val(response.width.toFixed(0));
+ $('#' + heightId).val(response.height.toFixed(0));
+ }
+ });
window.KCFinder = null;
}
};
<tr class="crm-badge-layout-form-block-image_1">
<td class="label">{$form.image_1.label}</td>
<td>
- {$form.image_1.html}
- <span class="crm-clear-link">
- (<a href="#" class="clear-image" imgname='image_1'>{ts}clear{/ts}</a>)
- </span>
- <br/><span class="description">{ts}Click above and select a file by double clicking on it.{/ts}</span>
+ <table>
+ <tr>
+ <td>{$form.image_1.html}
+ <span class="crm-clear-link">
+ (<a href="#" class="clear-image" imgname='image_1'>{ts}clear{/ts}</a>)
+ </span><br/>
+ <span class="description">{ts}Click above and select a file by double clicking on it.{/ts}</span>
+ </td>
+ <td>
+ {$form.width_image_1.html}<br/>{$form.width_image_1.label}
+ </td>
+ <td>
+ {$form.height_image_1.html}</br>{$form.height_image_1.label}
+ </td>
+ </tr>
+ </table>
</td>
</tr>
<tr class="crm-badge-layout-form-block-image_2">
<td class="label">{$form.image_2.label}</td>
<td>
- {$form.image_2.html}
- <span class="crm-clear-link">
- (<a href="#" class="clear-image" imgname='image_2'>{ts}clear{/ts}</a>)
- </span>
- <br/><span class="description">{ts}Click above and select a file by double clicking on it.{/ts}</span>
+ <table>
+ <tr>
+ <td>{$form.image_2.html}
+ <span class="crm-clear-link">
+ (<a href="#" class="clear-image" imgname='image_2'>{ts}clear{/ts}</a>)
+ </span><br/>
+ <span class="description">{ts}Click above and select a file by double clicking on it.{/ts}</span>
+ </td>
+ <td>
+ {$form.width_image_2.html}<br/>{$form.width_image_2.label}
+ </td>
+ <td>
+ {$form.height_image_2.html}<br/>{$form.height_image_2.label}
+ </td>
+ </tr>
+ </table>
</td>
</tr>
<tr class="crm-badge-layout-form-block-elements">