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
CGSmartImage used inside a custom module to generate images
- Eric Pesser
- Forum Members
- Posts: 27
- Joined: Mon Oct 13, 2008 8:59 am
- Location: Stavelot / Belgium
-
- Support Guru
- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
- Location: Fernie British Columbia, Canada
Re: CGSmartImage used inside a custom module to generate ima
You could probably do something like:
edit: came up with a better idea.
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;
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
- Eric Pesser
- Forum Members
- Posts: 27
- Joined: Mon Oct 13, 2008 8:59 am
- Location: Stavelot / Belgium
Re: CGSmartImage used inside a custom module to generate ima
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
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
- Eric Pesser
- Forum Members
- Posts: 27
- Joined: Mon Oct 13, 2008 8:59 am
- Location: Stavelot / Belgium
Re: CGSmartImage used inside a custom module to generate ima
Ok solved...
As I only manage jpg or png files, I found this solution :
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 .
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.
}
I don't know if it's the best solution, but it's works very well.
Then FPDF is finally happy, and me too .