[eluser]nmweb[/eluser]
Is it not possible to simply create a new instance of the image library? clear() isn't the neatest of solutions.
[eluser]Bramme[/eluser]
[quote author="nmweb" date="1216581969"]Is it not possible to simply create a new instance of the image library? clear() isn't the neatest of solutions.[/quote]
Haven't really got an opinion about the "neatness" off it, but it think the imglib would be handier if clear() got called before every initialize automatically.
[eluser]Rick Jolly[/eluser]
Absolutely Bramme. Why wouldn't the image lib call clear() before initialize()? The current implementation is awkward and results in this same question every week. I don't think allowing multiple instances is a good idea since libraries in CI are singletons for good reason and making one exception is an ugly hack.
[eluser]nmweb[/eluser]
Calling clear() before initialize() makes sense but is imho the ugly hack. You could as well do away with the whole class all the methods just functions stuck in a file, together with a bunch of variables in the global namespace. You probably gain performance and the functionality wouldn't differ from what's available now, only difference would be the pseudo-namespace achieved by using a class. An image or an email for that matter is a perfect example of a place where not to implement a singleton, after all, one might use more than one image in an application. Reusing the same object but clearing its data whenever you need a new image is awkward. I have argued before to allow loading without instantiation and in these cases that would be better code. Two images, two objects of the same Image class. A class should represent an objects characteristics (properties such as width, height etc.) and the stuff you can do with the object (the methods, resize, crop etc) Images are the perfect place to implement oop for and not stick to procedural code with oop syntax.
From my reading of the code (can't test it here right now), new instances are possible after the first loading of the class and I would strongly recommend that.
[eluser]KeyStroke[/eluser]
So shall I use multiple instances of the class to create multiple thumbnails of an image (and use clear() after each image), or is there another way around this?
I'm kind of confused 8-/
[eluser]Rick Jolly[/eluser]
-sek, substitute the second $this->load->library('image_lib', $config) with $this->image_lib->initialize();. CI won't create another instance because it maintains one singleton instance of all library classes. You can create another instance by writing $image_lib = new Image_lib();, but only after it has been loaded.