Welcome Guest, Not a member yet? Register   Sign In
uploading and using images

This class also figures out whether or not the image is portrait or landscape and resizes by ratio.


I think i can move on from here. This will be fun.

Thanks for showing me the path Wink

One more thing. Since the class resizes by ratio you only need to pass both width and height if you want to resize without constraining proportions. So if you pass only the width, depending on the layout of the image (portrait of landscape) the image will be resized by ratio.

so if you hade a portrait image (taller than wide) it would resize the height by the width you pass. This may seem confusing at first but it's really a great feature

To be specific, let's assume you have a portrait image that's 400w x 600h. If you resize the class like so:

This will resize the height of the image to 400 and size the width by ratio.

Oh yeah, one more thing. The class assumes that the file form has been submitted and the $_FILES data is already set. When you initiate the class and resize, it saves the image resource to the path you specify as per the modification I posted.

I'm gonna try sticking with the CI helper for upload, so i'll try to tweak the tmp path that you posted so it will get the image that is already there, resize it, and overwrite it.

I'll post by tomorrow the modification and how successful it went.

It's a great library! I liked the ratio example you did, good for those pictures that are high in the height.


Ok so here is the thing.

It works perfectly, it resizes but it's not maintaining the name there.

I'm using the CI upload helper because of the validation (errors) and the random hash it generates for the filename.
So my last resort will be implementing both on your library (the validation will be boring, the random hash renaming is easy).

Here's how i used:
//i call the upload somewhere before this and get the data after it's sent
$img_data = $this->upload->data();
//refence of upload->data
//    [file_name]    => mypic.jpg
//    [file_type]    => image/jpeg
//    [file_path]    => /path/to/your/upload/
//    [full_path]    => /path/to/your/upload/jpg.jpg
//    [raw_name]     => mypic
//    [orig_name]    => mypic.jpg
//    [file_ext]     => .jpg

Of course i'm using a resize_img function that does the code you posted passing those 3 parameters.

Now this is what is happening, consider i have the file with it's original name (the name that file has on my comp) like: my_picture.jpg
Then after using the CI upload helper the file is at public/images with the name: 2b0005c404f2.jpg
After using resize_img i get 2 files on /public/images:
my_picture.jpg (resized)
2b0005c404f2.jpg (not resized)

So you see what's going on here? It should have overwrited 2b0005c404f2.jpg, but it's taking again the original name and sending.

It's a detail, but interesting enough i don't know how to fix it.

I'm sure the problem is the first paramater i'm passing $img_data['orig_name'], but how to get the hash name of the picture?
upload->data(); doesn't return that..

Also sorry for my english, i've been reading my posts again and it looks terrible haha Big Grin

You're going to have to be more clear. I can't tell if you've renamed functions in my library or it's some other functions. My class saves the image it's constructed with and then operates on that image. If you rename the image after that, it's not going to overwrite the original saved image.

[quote author="textnotspeech" date="1221961573"]You're going to have to be more clear. I can't tell if you've renamed functions in my library or it's some other functions. My class saves the image it's constructed with and then operates on that image. If you rename the image after that, it's not going to overwrite the original saved image.[/quote]

For the upload i'm using CI upload helper, for resizing i'm using your great library.

The problem is exactly what you mentioned, the CI upload helper upload and then renames the image, so the imagination library is not overwriting. Can you think of anything that could help fixing this?

Maybe i should make a renaming function and add in imagination, but the problem is the validation that it was working so well with CI upload helper. It'd be a lot of trouble to add stuff like valid extensions, max height, max width, max size and set them all with $this->validation->error_string = 'MSG';

I hope you are following.

In short, this is what's happening:
1) I'm uploading an image with the name "my_picture.jpg"
2) CI upload helper uploads with the name: 2b0005c404f2.jpg
3) imagination resizes according to my parameters, but doesn't take the name so the end is:
(my images folderSmile
my_picture.jpg (resized <- imagination did this)
2b0005c404f2.jpg (not resized <- ci upload did this)

I just wish it would take 2b0005c..jpg and overwrite it instead.

My post above about "how i used", if you see the parameters, it's working since it is actually getting the image in the path and resizing, but it's not getting the img name.

Could you give me your opinion of how should i proceed with this?
Do you see the best approach?

My class validates the file type and the string_cleaning class cleans the filename of any garbage. My class is designed to handle an uploaded file, not one that exists already. Basically, I'm specifically not using CI's uploader.

When i talk about validation i mean max height, max width, max size etc all of that is covered with CI's uploader, one of the reasons i want to try to stick with it.

The class is not using CI's uploader, but I am and I am trying to make them both work together as handling a file that exists already uploaded on the server.

I just presented what I'm getting versus what I need to achieve and asked for your opinion about it, that's all.

But maybe I'm beeing boring here and asking too much.

I'm sure this won't be hard, so i'll work on this later and present how i succeeded since I don't want to bother you.

Thanks again textnotspeech! Sorry for the trouble.

Theme © iAndrew 2016 - Forum software by © MyBB