Page 1 of 1
CGSmartImage used inside a custom module to generate images
Posted: Tue Mar 12, 2013 12:07 am
by Eric Pesser
Hi,
For one of my customers, I have to print a custom module data list as a PDF.
As on webpage I use CGSmartImage, I would like to use it in my PHP code to generate better images for this (FPDF) output.
Is it possible? Does someone already did it?
Cheers,
Eric
Re: CGSmartImage used inside a custom module to generate ima
Posted: Tue Mar 12, 2013 1:32 am
by calguy1000
You could probably do something like:
Code: Select all
$mod = cms_utils::get_module('CGSmartImage'); // make sure the module is loaded
// build an array of params, same as the tag accepts
$params['src'] = '/path/relative/to/root/something.jpg';
$params['width'] = 100;
$params['height'] = 100;
$output = $mod->DoAction('xx','default',$returnid); // returnid can be any valid page id.
echo $output;
edit: came up with a better idea.
Re: CGSmartImage used inside a custom module to generate ima
Posted: Tue Mar 12, 2013 12:23 pm
by Eric Pesser
Thank you very much!
That helped me a lot.
Now I get an issue (not linked to this) because FPDF seems not to accept .img extension but it's another story.
Thanks again Robert.
Heriquet
Re: CGSmartImage used inside a custom module to generate ima
Posted: Tue Mar 12, 2013 11:20 pm
by Eric Pesser
Ok solved...
As I only manage jpg or png files, I found this solution :
Code: Select all
function ResizeImage($id, $pdfDirectory, $file, $width, $height)
{
$mod = cms_utils::get_module('CGSmartImage'); // make sure the module is loaded
// build an array of params, same as the tag accepts
$params['src'] = $file;
$params['width'] = $width;
$params['height'] = $height;
$params['notag'] = 1;
$params['noembed'] = 1;
$outp = cgsi_utils::process_image($params);
if( isset($outp['error']) && $outp['error'] != '')
{
// TODO: Manage error
return;
}
$image = $outp['output'];
// FPDF needs jpg, png or even gif, no img file so we copy img file content inside a new file with the original extension
$dir = pathinfo($file, PATHINFO_DIRNAME);
$filename = pathinfo($file, PATHINFO_FILENAME);
$ext = pathinfo($file, PATHINFO_EXTENSION);
$newimage = $pdfDirectory.$filename.'.'.$ext;
copy($image, $newimage);
return $newimage; // returnid can be any valid page id.
}
So I generate a new image using CGSI, then I copy this image and put the new image the original extension.
I don't know if it's the best solution, but it's works very well.
Then FPDF is finally happy, and me too

.