uploading and using images |
[eluser]textnotspeech[/eluser]
It's not CI's fault that you can't resize before saving. The GD library requires a source path and can't use a resource from a file upload. I built an image library that sends the image to another server via ftp after renaming and resizing several copies (thumbs etc.). I had to use a temp folder and then destroy all the local copies. I'm not in the office this week but when I get back I'd be glad to send you the code after I've cleaned it up for public consumption if you like.
[eluser]M4rc0[/eluser]
Yes please, I'm curious to check your code :d I have one here that i got from php.net and adapted that does the following: 1) Get the file from the form file field 2) Create a resized copy from the original 3) Upload with a new name So it doesn't need the path. I'm pasting the "secret" part of the code: Code: //get the $file parameter on the function Considering you pass the correct paramaters (the file field) it works perfectly. Although the code is good, i don't want to use it because i think it will be more trouble for me to adapt it than starting from zero. Everything is working here exept it's not resizing the image. After re-reading the image_lib documentation, i can't be sure of one thing: Is it possible to create a thumb AND resize the original image? It is creating the thumb but it's not resizing. Why? Where do i pass the resizing width and height parameters? Since the ones in $config are the width and height for the thumb. Could you confirm me that textnotspeech ? That would be my last try before adapating the code above
[eluser]textnotspeech[/eluser]
I totally sympathize with you on this one. The GD library is very finicky. If you can wait until tomorrow, I can give you my library for handling this. It sounds like you're trying to do the same thing I needed minus the ftp part. As for the code above, I would check all your variables and make sure the values are what you expect.
[eluser]M4rc0[/eluser]
textnotspeech, i don't want to sound pushy but any news about your library? I'm curious about it. Please, don't worry if that's trouble for you. If you don't reply today i'll take it you are busy or something, and i will doing a function for that. Thanks!
[eluser]textnotspeech[/eluser]
Sorry, I've been busy with clients. The class won't fit in this post. Here's a link Imagination Class w/validation and string cleaning. Put these in your libraries folder and load them like normal. The class is implemented like so: Code: $image = new Imagination($_FILES['image']['name'], $_FILES['image']['tmp_name']); Hope this helps. It's made for a specific purpose but can be customized to be more generic. It doesn't rename the actual filename so you'll have to make your own function for that.
[eluser]textnotspeech[/eluser]
The string_cleaning class and validation class are for sanitizing and validating the image name. These classes are fairly straight forward but let me know if you have any problems with it.
[eluser]M4rc0[/eluser]
Thanks! So this class also uploads the image? If yes, where do i set the upload path? If not, no problem. My upload_class is working really well. So let's say i have the picture there already and then i want to resize it. How would this be: Code: //$image = new Imagination($_FILES['image']['name'], $_FILES['image']['tmp_name']); Renaming is no problem either, the upload class is generating random hashes when it uploads.
[eluser]textnotspeech[/eluser]
Actually the path is set up as a temp directory. I'm only using one folder and not changing the path. You could add: Code: if($dir) After: Code: $this->tmp_dir = 'tmp/'; Code: public function __construct($image_name = FALSE, $image_src = FALSE) Code: public function __construct($image_name = FALSE, $image_src = FALSE, $dir = FALSE) Code: $image = new Imagination($_FILES['image']['name'], $_FILES['image']['tmp_name'], 'path');
[eluser]textnotspeech[/eluser]
Also, this class is set up for PHP 5 so you'll have to take out all the "public" and "private" declarations and change __construct to Imagination to make this work with PHP 4. |
Welcome Guest, Not a member yet? Register Sign In |