CGSmartImage used inside a custom module to generate images

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
User avatar
Eric Pesser
Forum Members
Forum Members
Posts: 27
Joined: Mon Oct 13, 2008 8:59 am
Location: Stavelot / Belgium

CGSmartImage used inside a custom module to generate images

Post 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
calguy1000
Support Guru
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

Post 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.
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.
User avatar
Eric Pesser
Forum Members
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

Post 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
User avatar
Eric Pesser
Forum Members
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

Post 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 ;).
Post Reply

Return to “Developers Discussion”