CodeIgniter Forums
Help with adding a custom plugin - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Help with adding a custom plugin (/showthread.php?tid=28655)



Help with adding a custom plugin - El Forum - 03-17-2010

[eluser]DumpProgrammer[/eluser]
I have an image resizer plugin that is usually loaded by using an include file on every page that its required. Here is the code you would use on your images
Code:
<IMG alt="" src="/scripts/timthumb.php?src=/images/whatever.jpg&h=150&w=150&zc=1">
Here is a link to to the script page. I need help with where I should put the custom php script whether it should be helper, library etc.


Help with adding a custom plugin - El Forum - 03-17-2010

[eluser]Jeremy Gimbel - Conflux Group[/eluser]
Before I answer your question, I wanted to mention that CI does in fact have a built-in image manipulation library. You may find what I'll explain below easier to implement using the native image manipulation library, as many of the steps would be the same anyway.

In order to incorporate a third-party library into CI, you'll often need to either modify the actual library or write a wrapper library that makes it fit into the CI scheme better. This can vary from library to library, and although it's not that complex, it does require that you understand a bit about how libraries work in CI. If you've got no clue what I'm talking about, I'd suggest ditching the third-party library and go with my above recommendation, using the native image manipulation library.

Regardless of whether you go third-party or native, you're going to need to build a controller with a method to handle generating the images. the '/scripts/timthumb.php' portion of the URL would then be replaced with controllername/methodname. Passing in the parameters can be done in a variety of ways, and I suggest you look at the CodeIgniter URLs section of the user guide if you don't understand how they work.

Basically, the method you write will accept the parameters for size and path and feed them to the library you're using to actually resize the image. The method would then output the resized image to the browser.

As a side note, I'd be cautious with using image generation improperly within your site. The process is definitely intensive as compared to normal server side operations for websites, so you definitely don't want to be generating new images for each page load of a heavily-used site.

Hope that's helpful.

jeremy


Help with adding a custom plugin - El Forum - 03-18-2010

[eluser]DumpProgrammer[/eluser]
Thanks for the help I am going to look into the CI image library and try to modify it into my requirements.

Thanks