Welcome Guest, Not a member yet? Register   Sign In
File upload and image resize all in one
#1

[eluser]Unknown[/eluser]
I'd like to resize images as they are uploaded. I've got uploading working fine but how do I intercept the upload data and perform the image resize? I imagine I'd need to create a new function in my upload controller to handle resizes and then somehow call that controller from the upload action? Maybe? Is that the best way to approach it? If so, how do you call one function from another within a class?
#2

[eluser]Unknown[/eluser]
OK, I solved my problem. Here is the solution for anyone else that may run into something related:
Quote:I imagine I’d need to create a new function in my upload controller to handle resizes
Correct. I created a function within the upload class called image_resize.
Quote:and then somehow call that controller...
I shouldn't have called it a controller... it is an action (a function within the class) and you make use of it from within a different action in the class as follows
Code:
$this->image_resize($the_image)
Quote:Is that the best way to approach it?
I doubt it since I still don't really get this object oriented stuff (things like what path to use to the image gave me headaches) but it works fine.

Oh, the path I used for the image resize
Code:
$config['source_image']
was
Code:
'uploads/'.$the_image
Note the lack of a preceding slash and also note that you don't use a url... use the actual path on your server (that is is the manual but I missed it the first time I read it). I first tried
Code:
'/uploads/'.$the_image
but that only confused me by failing Tongue




Theme © iAndrew 2016 - Forum software by © MyBB