FPDF image size - image

I'm using FPDF with PHP to add an image to a PDF and I want to put automatically the size of the image I find this function
function fctaffichimage($img_Src, $W_max, $H_max) {
if (file_exists($img_Src)) {
$img_size = getimagesize($img_Src);
$W_Src = $img_size[0]; // largeur source
$H_Src = $img_size[1]; // hauteur source
if(!$W_max) { $W_max = 0; }
if(!$H_max) { $H_max = 0; }
$W_test = round($W_Src * ($H_max / $H_Src));
$H_test = round($H_Src * ($W_max / $W_Src));
if($W_Src<$W_max && $H_Src<$H_max) {
$W = $W_Src;
$H = $H_Src;
} elseif($W_max==0 && $H_max==0) {
$W = $W_Src;
$H = $H_Src;
} elseif($W_max==0) {
$W = $W_test;
$H = $H_max;
} elseif($H_max==0) {
$W = $W_max;
$H = $H_test;
}
elseif($H_test > $H_max) {
$W = $W_test;
$H = $H_max;
} else {
$W = $W_max;
$H = $H_test;
}
}
}
but when i do
// requĂȘte
$tab1 = $_GET['tab1'];
$ID = $_GET['ID'];
$table = $_GET['table'];
$ree = "SELECT title,title2 FROM $tab1 WHERE $table = $ID ORDER BY 1";
$sql2 = mysql_query($ree);
// on affiche les deux images avec la fontion fctaffichimage
while ($roww = mysql_fetch_assoc($sql2))
{
$nomm = $roww["title"];
$url = "/var/www/images/".$nomm ;
fctaffichimage($url,100,100 );
$pdf->Cell(40,6,'',0,0,'C',$pdf->Image($img_Src,85,55));
}
it didn't work
I try to change the position of $url = "/var/www/images/".$nomm ;
fctaffichimage($url,100,100 ); but it didn't work too.

I see something I hope to help you. Put at the bottom of the function fctaffichimage the next code:
$img1 = imagecreatefrompng($img_Src);
$img2 = imagecreatetruecolor($W, $H);
imagecopyresampled($img2, $img1, 0, 0, 0, 0, $W, $H, $W_Src, $W_Src);
imagepng($img2, $img_Src);
Here I put a PNG image, but you can generalize it, depends of you need. It's running in my enviroment with PHP 5.3 (but there's a new imagescale function in PHP 5.5).

Related

Yii:Why images are not resized correctly ?

I am using image extension for image re sizing but they are not resized according to the parameters which i gave. Here is my code.Is there any mistake in my code or what. Images which are resized have dimension equal to "800*533"
but not exactly equals to 800*600.
public function actionCreate()
{
$model=new Business;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Business']))
{
$rnd = rand(0, 9999); // generate random number between 0-9999
$model->attributes = $_POST['Business'];
$uploadedFile = CUploadedFile::getInstance($model, 'image');
$fileName = "{$rnd}-{$uploadedFile}"; // random number + file name
$model->image = $fileName;
if ($model->save()) {
if(!empty($uploadedFile)) // check if uploaded file is set or not
{
//$uploadedFile->saveAs(Yii::getPathOfAlias('webroot')."/img".$filename);
$uploadedFile->saveAs(Yii::app()->basePath . '/../img/' . $fileName);
$image = Yii::app()->image->load(Yii::app()->basePath . '/../img/' . $fileName);
$image->resize(800, 600);
$image->save(Yii::app()->basePath . '/../img/' . $fileName);
}
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('create', array(
'model' => $model,
));
}
First advise. Don't store not resized image you can use
tempName property of CUploadedFile
$image = Yii::app()->image->load($uploadedFile->tempName );
$image->resize(800, 600);
$image->save(Yii::app()->basePath . '/../img/' . $fileName);
About resize i think you have to calculate size of resized picture.
Here is my code
protected static function getImgBox($img,$width,$height,$bySide,$boxType){
$img_width=$img->getSize()->getWidth();
$img_height=$img->getSize()->getHeight();
$newWidth =0;
$newHeight=0;
switch($boxType){
case self::BOX_TYPE_FILL:
{
$newWidth=$width;
$newHeight=$height;
}
break;
case self::BOX_TYPE_WO:{
if($bySide==self::BY_SIDE_WIDTH) {
$newWidth = $width;
$newHeight = $img_height * $newWidth / $img_width;
}
if($bySide==self::BY_SIDE_HEIGHT){
$newHeight=$height;
$newWidth = $img_width*$newHeight/$img_height;
}
}
break;
case self::BOX_TYPE_INSIDE:{
$newWidth = $width;
$newHeight = $img_height * $newWidth / $img_width;
if($newHeight>=$height){
$newHeight=$height;
$newWidth = $img_width*$newHeight/$img_height;
}
}
}
if($newHeight!=0 && $newWidth!=0){
return new Box(ceil($newWidth),ceil($newHeight));
}
else
return null;
}
I don't know witch extension you use. I use Imagine Extension for Yii 2
$imgpathlogo = App::param("upload_path").'outletlogo'. DIRECTORY_SEPARATOR;
$imgpathlogothumb100 = App::param("upload_path")."outletlogo". DIRECTORY_SEPARATOR."thumb100". DIRECTORY_SEPARATOR;
$imgpathlogothumb200 = App::param("upload_path")."outletlogo". DIRECTORY_SEPARATOR."thumb200". DIRECTORY_SEPARATOR;
///////////////////Chek Outlet New Logo Images////////////////
if ($_FILES['OutletMaster']['name']['outlet_logo'] != "") {
$imagelogo=$files['OutletMaster']['name']['outlet_logo'];
$logofilename=explode(".", $imagelogo);
$logofileext = $logofilename[count($logofilename) - 1];
$newlogofilename = uniqid(). "." . $logofileext;
$model->outlet_logo = $newlogofilename;
move_uploaded_file($_FILES['OutletMaster']['tmp_name']['outlet_logo'],$imgpathlogo.$newlogofilename);
//////////////////Creating Thumbnail For Outlet Logo///////////////////////////
$ext = explode(".", strtolower($newlogofilename))[1];
$src = $imgpathlogo.$newlogofilename;
if ($ext == 'gif')
$resource = imagecreatefromgif($src);
else if ($ext == 'png')
$resource = imagecreatefrompng($src);
else if ($ext == 'PNG')
$resource = imagecreatefrompng($src);
else if ($ext == 'jpg' || $ext == 'jpeg')
$resource = imagecreatefromjpeg($src);
$width = imagesx($resource);
$height = imagesy($resource);
$thumbWidth100 = 100;
$desired_width100 = $thumbWidth100;
$desired_height100 = floor( $height * ( $thumbWidth100 / $width ) );
$virtual_image = imagecreatetruecolor($desired_width100,$desired_height100);
imagecopyresized($virtual_image,$resource,0,0,0,0,$desired_width100,$desired_height100,$width,$height);
imagejpeg( $virtual_image, "{$imgpathlogothumb100}{$newlogofilename}" );
$thumbWidth200 = 200;
$desired_width200 = $thumbWidth200;
$desired_height200 = floor( $height * ( $thumbWidth200 / $width ) );
$virtual_image = imagecreatetruecolor($desired_width200,$desired_height200);
imagecopyresized($virtual_image,$resource,0,0,0,0,$desired_width200,$desired_height200,$width,$height);
imagejpeg( $virtual_image, "{$imgpathlogothumb200}{$newlogofilename}" );
}

GD blurry images Opencart

I have this problem with GD image processing in Opencart that creates real bad blurry images after resize. Nothing I have tried so far has helped.
Below is the code for the image.php
<?php
class Image {
private $file;
private $image;
private $info;
public function __construct($file) {
if (file_exists($file)) {
$this->file = $file;
$info = getimagesize($file);
$this->info = array(
'width' => $info[0],
'height' => $info[1],
'bits' => $info['bits'],
'mime' => $info['mime']
);
$this->image = $this->create($file);
} else {
exit('Error: Could not load image ' . $file . '!');
}
}
private function create($image) {
$mime = $this->info['mime'];
if ($mime == 'image/gif') {
return imagecreatefromgif($image);
} elseif ($mime == 'image/png') {
return imagecreatefrompng($image);
} elseif ($mime == 'image/jpeg') {
return imagecreatefromjpeg($image);
}
}
public function save($file, $quality = 100) {
$info = pathinfo($file);
$extension = strtolower($info['extension']);
if (is_resource($this->image)) {
if ($extension == 'jpeg' || $extension == 'jpg') {
imagejpeg($this->image, $file, $quality);
} elseif($extension == 'png') {
imagepng($this->image, $file);
} elseif($extension == 'gif') {
imagegif($this->image, $file);
}
imagedestroy($this->image);
}
}
/**
*
* #param width
* #param height
* #param default char [default, w, h]
* default = scale with white space,
* w = fill according to width,
* h = fill according to height
*
*/
public function resize($width = 0, $height = 0, $default = '') {
if (!$this->info['width'] || !$this->info['height']) {
return;
}
$xpos = 0;
$ypos = 0;
$scale = 1;
$scale_w = $width / $this->info['width'];
$scale_h = $height / $this->info['height'];
if ($default == 'w') {
$scale = $scale_w;
} elseif ($default == 'h'){
$scale = $scale_h;
} else {
$scale = min($scale_w, $scale_h);
}
if ($scale == 1 && $scale_h == $scale_w && $this->info['mime'] != 'image/png')
{
return;
}
$new_width = (int)($this->info['width'] * $scale);
$new_height = (int)($this->info['height'] * $scale);
$xpos = (int)(($width - $new_width) / 2);
$ypos = (int)(($height - $new_height) / 2);
$image_old = $this->image;
$this->image = imagecreatetruecolor($width, $height);
if (isset($this->info['mime']) && $this->info['mime'] == 'image/png') {
imagealphablending($this->image, false);
imagesavealpha($this->image, true);
$background = imagecolorallocatealpha($this->image, 255, 255, 255, 127);
imagecolortransparent($this->image, $background);
} else {
$background = imagecolorallocate($this->image, 255, 255, 255);
}
imagefilledrectangle($this->image, 0, 0, $width, $height, $background);
imagecopyresampled($this->image, $image_old, $xpos, $ypos, 0, 0, $new_width,
$new_height, $this->info['width'], $this->info['height']);
imagedestroy($image_old);
$this->info['width'] = $width;
$this->info['height'] = $height;
}
public function watermark($file, $position = 'bottomright') {
$watermark = $this->create($file);
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
switch($position) {
case 'topleft':
$watermark_pos_x = 0;
$watermark_pos_y = 0;
break;
case 'topright':
$watermark_pos_x = $this->info['width'] - $watermark_width;
$watermark_pos_y = 0;
break;
case 'bottomleft':
$watermark_pos_x = 0;
$watermark_pos_y = $this->info['height'] - $watermark_height;
break;
case 'bottomright':
$watermark_pos_x = $this->info['width'] - $watermark_width;
$watermark_pos_y = $this->info['height'] - $watermark_height;
break;
}
imagecopy($this->image, $watermark,
$watermark_pos_x, $watermark_pos_y, 0, 0, 120, 40);
imagedestroy($watermark);
}
public function crop($top_x, $top_y, $bottom_x, $bottom_y) {
$image_old = $this->image;
$this->image = imagecreatetruecolor($bottom_x - $top_x, $bottom_y - $top_y);
imagecopy($this->image, $image_old, 0, 0, $top_x, $top_y,
$this->info['width'], $this->info['height']);
imagedestroy($image_old);
$this->info['width'] = $bottom_x - $top_x;
$this->info['height'] = $bottom_y - $top_y;
}
public function rotate($degree, $color = 'FFFFFF') {
$rgb = $this->html2rgb($color);
$this->image = imagerotate($this->image, $degree,
imagecolorallocate($this->image, $rgb[0], $rgb[1], $rgb[2]));
$this->info['width'] = imagesx($this->image);
$this->info['height'] = imagesy($this->image);
}
private function filter($filter) {
imagefilter($this->image, $filter);
}
private function text($text, $x = 0, $y = 0, $size = 5, $color = '000000') {
$rgb = $this->html2rgb($color);
imagestring($this->image, $size, $x, $y, $text,
imagecolorallocate($this->image, $rgb[0], $rgb[1], $rgb[2]));
}
private function merge($file, $x = 0, $y = 0, $opacity = 100) {
$merge = $this->create($file);
$merge_width = imagesx($image);
$merge_height = imagesy($image);
imagecopymerge($this->image, $merge, $x, $y, 0, 0, $merge_width,
$merge_height, $opacity);
}
private function html2rgb($color) {
if ($color[0] == '#') {
$color = substr($color, 1);
}
if (strlen($color) == 6) {
list($r, $g, $b) = array($color[0] . $color[1], $color[2] . $color[3],
$color[4] . $color[5]);
} elseif (strlen($color) == 3) {
list($r, $g, $b) = array($color[0] . $color[0], $color[1] . $color[1],
$color[2] . $color[2]);
} else {
return false;
}
$r = hexdec($r);
$g = hexdec($g);
$b = hexdec($b);
return array($r, $g, $b);
}
}
?>
As you can see the quality is already set to 100 , so that doesn't help.
I have tried replacing resize with resample - but that produced no visible result.
However I have found this suggestion (code below) to sharpen images, unfortunately I am not sure how and where to use it. Especially since original code processed multiple image types. Please help to put this in the right place.
{
$matrix = array(
array(-1, -1, -1),
array(-1, 16, -1),
array(-1, -1, -1),
);
$divisor = array_sum(array_map('array_sum', $matrix));
$offset = 0;
imageconvolution($image, $matrix, $divisor, $offset);
return $image;
}
Also, if you have other suggestions to improve this code, help is greatly appreciated! I think that goes for the whole Opencart community, as this has been discussed many time but no working solution posted as of yet.
The quality parameter will only be applicable to .jpeg images.
To sharpen the images you could apply the imageconvolution() code within the resize() function.
public function resize($width = 0, $height = 0, $default = '') {
if (!$this->info['width'] || !$this->info['height']) {
return;
}
$xpos = 0;
$ypos = 0;
$scale = 1;
$scale_w = $width / $this->info['width'];
$scale_h = $height / $this->info['height'];
if ($default == 'w') {
$scale = $scale_w;
} elseif ($default == 'h') {
$scale = $scale_h;
} else {
$scale = min($scale_w, $scale_h);
}
if ($scale == 1 && $scale_h == $scale_w && $this->info['mime'] != 'image/png') {
return;
}
$new_width = (int)($this->info['width'] * $scale);
$new_height = (int)($this->info['height'] * $scale);
$xpos = (int)(($width - $new_width) / 2);
$ypos = (int)(($height - $new_height) / 2);
$image_old = $this->image;
$this->image = imagecreatetruecolor($width, $height);
if (isset($this->info['mime']) && $this->info['mime'] == 'image/png') {
imagealphablending($this->image, false);
imagesavealpha($this->image, true);
$background = imagecolorallocatealpha($this->image, 255, 255, 255, 127);
imagecolortransparent($this->image, $background);
} else {
$background = imagecolorallocate($this->image, 255, 255, 255);
}
imagefilledrectangle($this->image, 0, 0, $width, $height, $background);
imagecopyresampled($this->image, $image_old, $xpos, $ypos, 0, 0, $new_width, $new_height, $this->info['width'], $this->info['height']);
//Image Sharpening Code
$matrix = array(
array(0.0, -1.0, 0.0),
array(-1.0, 5.0, -1.0),
array(0.0, -1.0, 0.0)
);
$divisor = array_sum(array_map('array_sum', $matrix));
$offset = 0;
imageconvolution($this->image, $matrix, $divisor, $offset);
// End Image Sharpening Code
imagedestroy($image_old);
$this->info['width'] = $width;
$this->info['height'] = $height;
}
References:
sharpen image quality with PHP gd library
http://adamhopkinson.co.uk/blog/2010/08/26/sharpen-an-image-using-php-and-gd/

how to resize my water mark

my image is :
http://img.majidonline.com/pic/309603/02.png
and my watermark image is:
http://img.majidonline.com/thumb/309602/01.png
my water mark file is normal. but i Want when my image is big my watermark be big.
this is my watermark result:
http://img.majidonline.com/pic/309604/03.png
I want my image watermarked be like this one:
http://img.majidonline.com/pic/309605/04.png
And this is my class for watermark:
<?php
#################################################################################
# Watermark Image Class 1.0
#################################################################################
# For updates visit http://www.zubrag.com/scripts/
#################################################################################
#
# REQUIREMENTS:
# PHP 4.0.6 and GD 2.0.1 or later
# May not work with GIFs if GD2 library installed on your server
# does not support GIF functions in full
#
#################################################################################
class Zubrag_watermark {
var $offset_x = 0;
var $offset_y = 0;
var $quality = 0;
var $image_type = -1; // Image type: 1 = GIF, 2 = JPG, 3 = PNG
var $force_image_type = 3; // Change image type? (-1 = same as original, 1 = GIF, 2 = JPG, 3 = PNG)
var $save_to_file = true;
function Zubrag_watermark($image_path='', $offset_x=0, $offset_y=0) {
$this->setImagePath($image_path);
$this->setOffset($offset_x, $offset_y);
}
function setImagePath($image_path) {
$this->image_path = $image_path;
}
function setOffset($x, $y) {
$this->offset_x = $x;
$this->offset_y = $y;
}
function ImageCreateFromType($type,$filename) {
$im = null;
switch ($type) {
case 1:
$im = ImageCreateFromGif($filename);
break;
case 2:
$im = ImageCreateFromJpeg($filename);
break;
case 3:
$im = ImageCreateFromPNG($filename);
break;
}
return $im;
}
function ApplyWatermark($watermark_path, $wwidth, $wheight) {
$this->watermark_path = $watermark_path;
// Determine image size and type
$size = getimagesize($this->image_path);
$size_x = $size[0];
$size_y = $size[1];
$image_type = $size[2]; // 1 = GIF, 2 = JPG, 3 = PNG
// load source image
$image = $this->ImageCreateFromType($image_type, $this->image_path);
// Determine watermark size and type
$wsize = getimagesize($watermark_path);
$watermark_x = $wsize[0];
$watermark_y = $wsize[1];
$watermark_type = $wsize[2]; // 1 = GIF, 2 = JPG, 3 = PNG
// load watermark
$watermark = $this->ImageCreateFromType($watermark_type, $watermark_path);
// where do we put watermark on the image?
$dest_x = $size_x - $watermark_x - $this->offset_x;
$dest_y = $size_y - $watermark_y - $this->offset_y;
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_x, $watermark_y, 100);
$this->image = &$image;
$this->watermark = &$watermark;
$this->image_type = $image_type;
} // ApplyWatermark
function OutputImageInternal($filename='') {
$im = &$this->image;
$res = null;
$image_type = ($this->force_image_type != -1 ? $this->force_image_type : $this->image_type);
// ImageGIF is not included into some GD2 releases, so it might not work
// output png if gifs are not supported
if(($image_type == 1) && !function_exists('imagegif')) $image_type = 3;
switch ($image_type) {
case 1:
if ($this->save_to_file) {
$res = ImageGIF($im,$filename);
}
else {
header("Content-type: image/gif");
$res = ImageGIF($im);
}
break;
case 2:
if ($this->save_to_file) {
$res = ImageJPEG($im,$filename,$this->quality);
}
else {
header("Content-type: image/jpeg");
$res = ImageJPEG($im, NULL, $this->quality);
}
break;
case 3:
if (PHP_VERSION >= '5.1.2') {
// Convert to PNG quality.
// PNG quality: 0 (best quality, bigger file) to 9 (worst quality, smaller file)
$quality = 9 - min( round($this->quality / 10), 9 );
if ($this->save_to_file) {
$res = ImagePNG($im, $filename, $quality);
}
else {
header("Content-type: image/png");
$res = ImagePNG($im, NULL, $quality);
}
}
else {
if ($this->save_to_file) {
$res = ImagePNG($im, $filename);
}
else {
header("Content-type: image/png");
$res = ImagePNG($im);
}
}
break;
}
return $res;
}
function Output($type = -1) {
$this->force_image_type = $type;
$this->save_to_file = false;
$this->OutputImageInternal();
}
function SaveAsFile($filename, $type = -1) {
$this->force_image_type = $type;
$this->save_to_file = true;
$this->OutputImageInternal($filename);
}
function Free() {
imagedestroy($this->image);
imagedestroy($this->watermark);
}
}
?>
please say me where i can change watermark size?
Just make your watermark bigger in photoshop.

Generate pdf of wishlist items in magento

Can anyone guide me how to generate pdf of wishlist items (products) in magento?
Wrap this code in your custom controller.
public function whishlistAction()
{
$session = Mage::getSingleton('customer/session', array('name'=>'frontend'));
if(!$session->isLoggedIn())
{
$this->_redirect(Mage::getUrl('customer/account'));
}
$customer = Mage::getModel('customer/customer')->load($session->getId());
$wishList = Mage::getModel('wishlist/wishlist')->loadByCustomer($customer);
$wishListItemCollection = $wishList->getItemCollection();
$pdf = new Zend_Pdf();
$pageCount = 0;
$collectionPreperedForPagesKey=0;
$collectionPreperedForPages = array();
foreach ($wishListItemCollection as $w)
{
$pageCount = $pageCount+1;
if($pageCount==4)
{
$collectionPreperedForPagesKey=$collectionPreperedForPagesKey+1;
$pageCount=0;
}
$collectionPreperedForPages[$collectionPreperedForPagesKey][]=$w;
}
foreach ($collectionPreperedForPages as $c)
{
$pdf->pages[] = $this->createWhishlistPage($c);
}
$pdfString = $pdf->render();
header("Content-Disposition: attachment; filename=whishlist.pdf");
header("Content-type: application/x-pdf");
echo $pdfString;
exit;
}
public function getImagePath($product)
{
$imageUrl = Mage::getModel('catalog/product_media_config')
->getMediaUrl( $product->getImage() );
$baseDir = Mage::getBaseDir() ;
$withoutIndex = str_replace('index.php/','', Mage::getBaseUrl());
$imageWithoutBase = str_replace($withoutIndex,'' , $imageUrl);
$imagePath = $baseDir.DIRECTORY_SEPARATOR.$imageWithoutBase ;
return $imagePath;
}
public function getImageSizesWithAspectRatio($widthImage,$heightImage,$widthBox,$heightBox)
{
if (($widthBox >= $widthImage) && ($heightBox >= $heightImage))
{
return array('width'=>$widthImage,'height'=>$heightImage);
}
$resizeRatio = 1;
if($widthBox < $widthImage)
{
$resizeRatio = $widthImage/$widthBox;
$widthImage = $widthBox;
}
if($heightBox < $heightImage)
{
if($resizeRatio!=1)
{
$heightImage = $heightImage/$resizeRatio;
}
if($heightImage>$heightBox)
{
$resizeRatio = $heightImage/$heightBox;
$heightImage = $heightBox;
$widthImage = $widthImage/$resizeRatio;
}
}
return array('width'=>$widthImage,'height'=>$heightImage);
}
public function createWhishlistPage($wishListItemCollection)
{
$lightFont = Zend_Pdf_Font::fontWithPath($this->getFont('light'));
$regularFont = Zend_Pdf_Font::fontWithPath($this->getFont('regular'));
$boldFont = Zend_Pdf_Font::fontWithPath($this->getFont('bold'));
$page1 = new Oxidian_Pdf_Helper_Page(Zend_Pdf_Page::SIZE_A4);
$page1->setFillColor(Zend_Pdf_Color_Html::color('#75645E'));
$page1->setLineColor(Zend_Pdf_Color_Html::color('#75645E'));
$page1->setLineWidth(1);
$headerFontSize = 40;
$headerLeft = 20;
$headerTop = $page1->getHeight()-$headerFont-50;
$page1->setFont($lightFont, $headerFontSize);
$contentTopFreeSpace = $headerTop-70;
$contentLeft = 20;
$contentRight = $page1->getWidth()-20;
$page1->drawText('JORDAN', $headerLeft,$headerTop);
$page1->setFont($regularFont, $headerFontSize/2);
$page1->drawText('My dreamboard', $page1->getWidth()/2+40,$headerTop);
$tableHeaderFont = 15;
$page1->setFont($boldFont, $tableHeaderFont);
$columnHeaderPadding = 5;
$productColumnSize = 100;
$previewColumnSize = 100;
$imagePreviewSize = 100;
$previewTableHeaderPosition = $columnHeaderPadding+$productColumnSize+$contentLeft;
$commentTableHeaderPosition = $previewTableHeaderPosition+$previewColumnSize+$columnHeaderPadding;
$productTableHeaderPosition = columnHeaderPadding+$contentLeft;
$commentColumnSize = $page1->getWidth()-$commentTableHeaderPosition ;
$page1->drawText('Product', $productTableHeaderPosition ,$contentTopFreeSpace);
$page1->drawText('Preview', $previewTableHeaderPosition,$contentTopFreeSpace);
$page1->drawText('Comments', $commentTableHeaderPosition,$contentTopFreeSpace);
$paddingRowHeaderFromLine = 5;
$contentTopFreeSpace = $contentTopFreeSpace-$paddingRowHeaderFromLine;
$tableStart = $contentTopFreeSpace;
$contentFont = 15;
$rowHeight= 125;
$page1->setFont($regularFont, $contentFont);
foreach($wishListItemCollection as $w)
{
$page1->drawLine($contentLeft,$contentTopFreeSpace ,$contentRight,$contentTopFreeSpace);
$contentTopFreeSpace =$contentTopFreeSpace- $contentFont-$paddingRowHeaderFromLine;
$product = $w->getProduct();
$product = Mage::getModel('catalog/product')->load($product->getId());
$page1->drawTextBlock($product->getName(), $productTableHeaderPosition,$contentTopFreeSpace,$productColumnSize);
$page1->drawTextBlock($w->getDescription(), $commentTableHeaderPosition,$contentTopFreeSpace,$commentColumnSize);
$imagePath = $this->getImagePath($product);
// Load image
$image = Zend_Pdf_Image::imageWithPath($imagePath);
$imageObj = new Varien_Image($imagePath);
$imageSizes = $this->getImageSizesWithAspectRatio($imageObj->getOriginalWidth(),$imageObj->getOriginalHeight(),$imagePreviewSize,$rowHeight);
$imageBottom = ($rowHeight-$imageSizes['height'])+$contentTopFreeSpace;
$imageLeft = $previewTableHeaderPosition;
$page1->drawImage($image,$imageLeft,$imageBottom-$imageSizes['height'],$previewTableHeaderPosition+$imageSizes['width'],$contentTopFreeSpace);
$contentTopFreeSpace = $contentTopFreeSpace-$rowHeight-$paddingRowHeaderFromLine;
$page1->drawLine($contentLeft,$contentTopFreeSpace ,$contentRight,$contentTopFreeSpace);
};
$tableLineProductsStartX = $previewTableHeaderPosition-$columnHeaderPadding;
$tableLineProductsStartY = $tableStart+$paddingRowHeaderFromLine+$tableHeaderFont;
$tableLineProductsStartX1 = $previewTableHeaderPosition-$columnHeaderPadding;
$tableLineProductsStartY1 = $contentTopFreeSpace;
$tableLinePreviewStartX = $commentTableHeaderPosition-$columnHeaderPadding;
$tableLinePreviewStartY = $tableStart+$paddingRowHeaderFromLine+$tableHeaderFont;
$tableLinePreviewStartX1 = $commentTableHeaderPosition-$columnHeaderPadding;
$tableLinePreviewStartY1 = $contentTopFreeSpace;
$page1->drawLine($tableLineProductsStartX ,$tableLineProductsStartY ,$tableLineProductsStartX1,$tableLineProductsStartY1);
$page1->drawLine($tableLinePreviewStartX ,$tableLinePreviewStartY ,$tableLinePreviewStartX1,$tableLinePreviewStartY1);
return $page1;
}
Source: http://gorrc.blogspot.in/2012/05/magento-print-whishlist-to-pdf.html

How resize image in Joomla?

I try use this:
$image = new JImage();
$image->loadFile($item->logo);
$image->resize('208', '125');
$properties = JImage::getImageFileProperties($item->logo);
echo $image->toFile(JPATH_CACHE . DS . $item->logo, $properties->type);
But not work =\ any idea?
Try this out:
// Set the path to the file
$file = '/Absolute/Path/To/File';
// Instantiate our JImage object
$image = new JImage($file);
// Get the file's properties
$properties = JImage::getImageFileProperties($file);
// Declare the size of our new image
$width = 100;
$height = 100;
// Resize the file as a new object
$resizedImage = $image->resize($width, $height, true);
// Determine the MIME of the original file to get the proper type for output
$mime = $properties->mime;
if ($mime == 'image/jpeg')
{
$type = IMAGETYPE_JPEG;
}
elseif ($mime == 'image/png')
{
$type = IMAGETYPE_PNG;
}
elseif ($mime == 'image/gif')
{
$type = IMAGETYPE_GIF;
}
// Store the resized image to a new file
$resizedImage->toFile('/Absolute/Path/To/New/File', $type);

Resources