class.upload.php is a powerful and mature PHP class to manage uploaded files, and manipulate images in many ways. The script is available under a GPL license.
I'm testing this now and I got it working fine if I for example upload a gif and convert it to a jpg.
BUT ... Next test I have problem with. I don't want the images saved as a files, I just want to convert uploaded images to jpg and then store it in a variable for later insert into a db. I assume jpg at average gives smallest images to save into my db... FYI ... I will be using this in my users gallery area ... I had all image files saved on disk before, but I'm changing to store images in db now ...
Anyway, when I test using the code below, and upload a gif it looks like the resulting image is a huge bmp ... Not a jpg ... At least that's what I get when I right click and saving it ... Any idea what I'm doing wrong and what I should do?
if ($handle->uploaded) {
$handle->file_new_name_body = 'image_resized';
$handle->image_convert = 'jpg'; // We only want jpg's saved into db ...
$handle->image_resize = true;
$handle->image_x = 255;
$handle->image_ratio_y = true;
$handle->jpeg_quality = 80;
$handle->Process('./images/upload/');
$image = $handle->Process();
if ($handle->processed) {
header('Content-type: ' . $handle->file_src_mime);
echo $image;
} else {
echo 'error : ' . $handle->error;
}
}
You need to call process() only once. You can remove the first call to process().
After the first call to process(), the variables are reinitialized, and the second call to process() will "upload" the picture without any resizing.
So here in your code, you store the resized JPEG image on disk, and then you secondly get untreated image in the database. This is why the second image appears large; in fact, it is your original image that you get in the second call to process().Reply
Re: Problem converting images to screen / variable ... new!
I saw I forgot to take out the first call in my sample just after I posted ;-)
So, what you say is I have to store the converted/resized image on disk first, then read it into a variable for further processing, like store it into the db etc ... Correct ?
This I got working just fine in my tests so I guess I can proceed then :) Thank's for a great tool and super great support and responce time!
FYI ... I spent last few days looking all over for something like this and I found quite a few similar tools, but nothing I was too happy with ... Until I found out about you and class.upload !!!
No, what I am saying is that you can either: - call process() once, without any argument, in order to get the image content, and store in in the database. - call process() a first time to store the file on disk, and then call it a second time to store the image in the database.
You probably want the first solution, since I don't think that you need to also store the file on disk. You don't need to store the file on disk to read it back and store it in the database. Calling process() without argument does that for you (without even storing the image on disk).
And if you like the class so much, feel free to spread the word about it! And if you like my response time, also feel free to support the class by donating ;)Reply
Re: Problem converting images to screen / variable ... new!
BUT ... Next test I have problem with.
I don't want the images saved as a files, I just want to convert uploaded images to jpg and then store it in a variable for later insert into a db. I assume jpg at average gives smallest images to save into my db... FYI ... I will be using this in my users gallery area ... I had all image files saved on disk before, but I'm changing to store images in db now ...
Anyway, when I test using the code below, and upload a gif it looks like the resulting image is a huge bmp ... Not a jpg ... At least that's what I get when I right click and saving it ... Any idea what I'm doing wrong and what I should do?
After the first call to process(), the variables are reinitialized, and the second call to process() will "upload" the picture without any resizing.
So here in your code, you store the resized JPEG image on disk, and then you secondly get untreated image in the database. This is why the second image appears large; in fact, it is your original image that you get in the second call to process().
So, what you say is I have to store the converted/resized image on disk first, then read it into a variable for further processing, like store it into the db etc ... Correct ?
This I got working just fine in my tests so I guess I can proceed then :)
Thank's for a great tool and super great support and responce time!
FYI ... I spent last few days looking all over for something like this and I found quite a few similar tools, but nothing I was too happy with ... Until I found out about you and class.upload !!!
Lucky me ;-)
Thanks Colin!!!
- call process() once, without any argument, in order to get the image content, and store in in the database.
- call process() a first time to store the file on disk, and then call it a second time to store the image in the database.
You probably want the first solution, since I don't think that you need to also store the file on disk. You don't need to store the file on disk to read it back and store it in the database. Calling process() without argument does that for you (without even storing the image on disk).
And if you like the class so much, feel free to spread the word about it! And if you like my response time, also feel free to support the class by donating ;)
Sure I'll help u spread the word and sure ... donation will come later on :)
Take care!
/Stefan