- Posts: 7
COMMUNITY FORUM
Content Module Image resizing
- Gerard Croteau
-
- Offline
- New Member
I'm happy that some of you shared their ideas about this problem. After a while, I tought it could be an incompatibility with a template. I tried with several templates. No way, K2 still not resizing any images. Do I have to understand that a PHP GD library has to be installed on the server ? I don't know that stuff, I'm a end user. Should I ask to my hoster to invest time to let me use K2 ?
For me, even I like K2, the fact that I can't resize any images, whatever the setup I use in the setup panels, is really anoying. I hope to get a solution soon, as we have to make a final decision to use or not K2, and look for an alternative. I'm sad as I invested serveral hours to learn it and I would'nt like to start a new process.
K2 refuse to resize any images. That's all ! whatever I played with all the possible set up options. Thank you for your ideas and help.
Richard Pigden said:Hi Lefteris
I think this is just a case of me being an idiot! I had made the assumption K2 would resize any image added within the Item text but of course that is not the case - it will only resize the image that you upload via the Image tab, and that works perfectly!
My apologies for not realising this sooner and wasting your time.
Richard
Please Log in or Create an account to join the conversation.
- Rune Christensen
-
- Offline
- New Member
- Posts: 2
Please Log in or Create an account to join the conversation.
- Lefteris
-
- Offline
- Platinum Member
- Posts: 8743
Gerard Croteau said:Fellow K2 adepts and friends
I'm happy that some of you shared their ideas about this problem. After a while, I tought it could be an incompatibility with a template. I tried with several templates. No way, K2 still not resizing any images. Do I have to understand that a PHP GD library has to be installed on the server ? I don't know that stuff, I'm a end user. Should I ask to my hoster to invest time to let me use K2 ?
For me, even I like K2, the fact that I can't resize any images, whatever the setup I use in the setup panels, is really anoying. I hope to get a solution soon, as we have to make a final decision to use or not K2, and look for an alternative. I'm sad as I invested serveral hours to learn it and I would'nt like to start a new process.
K2 refuse to resize any images. That's all ! whatever I played with all the possible set up options. Thank you for your ideas and help.
Richard Pigden said:Hi Lefteris I think this is just a case of me being an idiot! I had made the assumption K2 would resize any image added within the Item text but of course that is not the case - it will only resize the image that you upload via the Image tab, and that works perfectly!
My apologies for not realising this sooner and wasting your time.
Richard
Please Log in or Create an account to join the conversation.
- Gerard Croteau
-
- Offline
- New Member
- Posts: 7
I still have the same problem and I have to consider other tools than K2 as this bog don't let me edit adequalty my blog
Rune Christensen said:I had this problem and switching back to php 5.2 from 5.3 did the job!
Please Log in or Create an account to join the conversation.
- Gerard Croteau
-
- Offline
- New Member
- Posts: 7
Thank you for your help
Please Log in or Create an account to join the conversation.
- Nick Texidor
-
- Visitor
Hi all, I'm going to post this here in the hopes that the K2 developers can incorporate this into K2, but also in the hopes others will find my solution. I've also emailed the developer of class.upload.php in the hopes he can fix the error.
I've been having problems with images being uploaded and resized by the class.upload.php script that K2 uses. I've experienced the problem with the file prefixes missing, and I've run into problems within my own extensions where images need to be resized, but fails because PECL reports the MIME type as audio/x-mod.
After pulling the whole process apart, there is a fairly 'fundamental' problem with class.upload.php (v0.29 as used by K2 2.3): The init function is called after you start the upload. Therefore, any parameters you set, required by the upload function, are re-initialised.
I fixed this as follows:
In the class.upload.php file, head down to where you see:
function upload($file, $lang = 'en_GB') {
$this->version = '0.29';
$this->file_src_name = '';
$this->file_src_name_body = '';
$this->file_src_name_ext = '';
$this->file_src_mime = '';
$this->file_src_size = '';
$this->file_src_error = '';
$this->file_src_pathname = '';
$this->file_src_temp = '';
$this->file_dst_path = '';
$this->file_dst_name = '';
$this->file_dst_name_body = '';
$this->file_dst_name_ext = '';
$this->file_dst_pathname = '';
$this->image_src_x = null;
$this->image_src_y = null;
$this->image_src_bits = null;
$this->image_src_type = null;
$this->image_src_pixels = null;
$this->image_dst_x = 0;
$this->image_dst_y = 0;
$this->uploaded = true;
$this->no_upload_check = false;
$this->processed = true;
$this->error = '';
$this->log = '';
$this->allowed = array();
$this->forbidden = array();
$this->file_is_image = false;
$this->init();
$info = null;
$mime_from_browser = null;
etc.....
and change it to this:
function __construct() {
$this->version = '0.29';
$this->file_src_name = '';
$this->file_src_name_body = '';
$this->file_src_name_ext = '';
$this->file_src_mime = '';
$this->file_src_size = '';
$this->file_src_error = '';
$this->file_src_pathname = '';
$this->file_src_temp = '';
$this->file_dst_path = '';
$this->file_dst_name = '';
$this->file_dst_name_body = '';
$this->file_dst_name_ext = '';
$this->file_dst_pathname = '';
$this->image_src_x = null;
$this->image_src_y = null;
$this->image_src_bits = null;
$this->image_src_type = null;
$this->image_src_pixels = null;
$this->image_dst_x = 0;
$this->image_dst_y = 0;
$this->uploaded = true;
$this->no_upload_check = false;
$this->processed = true;
$this->error = '';
$this->log = '';
$this->allowed = array();
$this->forbidden = array();
$this->file_is_image = false;
$this->init();
}
function doUpload($file, $lang = 'en_GB') {
$info = null;
$mime_from_browser = null;
etc....
Then in your joomla extension/K2 code, you make a slight modification, change:
$handle->upload($file);
to
$handle = new upload();
$handle->doUpload($file);
Now, if you have MIME problems thanks to PECL, you can disable it with:
$handle = new upload();
$handle->mime_fileinfo = false;
$handle->doUpload($file);
I've just tried all this code, and my images are now resizing correctly.
I've attached my 'fixed' file to this message, just search for NICKS FIX to see where the code has been changed & repaired.
Hope this helps
Regards
Nick
Please Log in or Create an account to join the conversation.
- Mongo
-
- Offline
- Junior Member
- Posts: 32
Thank you dude I just thought people just saying I was crazy was true!.. I mean I hide it well but hehe.. But thank you for looking into such an old thread. I really appreciate it and i'm now using your file.
Please Log in or Create an account to join the conversation.
- Nick Texidor
-
- Visitor
I heard back from Colin, who pretty much replied with "your fix isn't backward compatible with PHP4", gee.. all that work and that's the response??
Anyway, to make it backward compatible with PHP4, if anyone is still running it... simply change __construct to upload and you should be fine. Personally, I reckon you've got more issues than this if you're still running php4 :^)
All the best
N
Mongo said:Wow You Are The Man!!
Thank you dude I just thought people just saying I was crazy was true!.. I mean I hide it well but hehe.. But thank you for looking into such an old thread. I really appreciate it and i'm now using your file.
Please Log in or Create an account to join the conversation.
- Nick Texidor
-
- Visitor
/administrator/components/com_k2/models/category.php
/administrator/components/com_k2/models/item.php
/administrator/components/com_k2/models/user.php
/plugins/user/k2.php
In those files, simply replace all occurrences of:
$handle = new Upload($file);
with:
$handle = new upload();
$handle->mime_fileinfo = false;
$handle->doUpload($file);
and everything should be sweet! :^)
Mongo said:Wow You Are The Man!!
Thank you dude I just thought people just saying I was crazy was true!.. I mean I hide it well but hehe.. But thank you for looking into such an old thread. I really appreciate it and i'm now using your file.
Please Log in or Create an account to join the conversation.
- Mongo
-
- Offline
- Junior Member
- Posts: 32
But yes your code is working fine with no issues, and I really appreciate it
Please Log in or Create an account to join the conversation.
- Joackim Devaud
-
- Offline
- New Member
- Posts: 3
First, thank you for your solution... ;-)
I've changed all the line in all the files and i still have an error "file error, please try again"...
Could you upload all the files you've changed? It will be very usefull for me...
Thx for your answer...
Best Regards
Nick Texidor said:Hey Mongo, sorry to send yet another message. I forgot to mention that there are 4 files in K2 that need changing if you want them all to work properly:
/administrator/components/com_k2/models/category.php
/administrator/components/com_k2/models/item.php
/administrator/components/com_k2/models/user.php
/plugins/user/k2.php
In those files, simply replace all occurrences of:
$handle = new Upload($file);
with:
$handle = new upload();
$handle->mime_fileinfo = false;
$handle->doUpload($file);
and everything should be sweet! :^)
Mongo said:Wow You Are The Man!! Thank you dude I just thought people just saying I was crazy was true!.. I mean I hide it well but hehe.. But thank you for looking into such an old thread. I really appreciate it and i'm now using your file.
Please Log in or Create an account to join the conversation.
- Nick Texidor
-
- Visitor
I guess the first thing to do is actually check that your error is related to the MIME type checking. Looking at the error message you mentioned, and going through the uploader class code, It looks like the error is more related to the upload of the file.
Anyway, there is some debug code in the upload class that may help out. Which section are you uploading from? If it's adding an image to a K2 item, then open the /administrator/components/com_k2/models/item.php file. Search for $handle, and it should take you down to the code that fires off the upload script. Just before the if ($handle->uploaded) check, try putting in echo $handle->log and see if there are any helpful messages there.
If you're still having problems, send me a private message and we can take this private to try and help you out.
All the best
Nick
Joackim Devaud said:Hello Nick,
First, thank you for your solution... ;-)
I've changed all the line in all the files and i still have an error "file error, please try again"...
Could you upload all the files you've changed? It will be very usefull for me...
Thx for your answer...
Best Regards
Nick Texidor said:Hey Mongo, sorry to send yet another message. I forgot to mention that there are 4 files in K2 that need changing if you want them all to work properly: /administrator/components/com_k2/models/category.php
/administrator/components/com_k2/models/item.php
/administrator/components/com_k2/models/user.php
/plugins/user/k2.php
In those files, simply replace all occurrences of:
$handle = new Upload($file);
with:
$handle = new upload();
$handle->mime_fileinfo = false;
$handle->doUpload($file);
and everything should be sweet! :^)
Mongo said:Wow You Are The Man!! Thank you dude I just thought people just saying I was crazy was true!.. I mean I hide it well but hehe.. But thank you for looking into such an old thread. I really appreciate it and i'm now using your file.
Please Log in or Create an account to join the conversation.
- Joackim Devaud
-
- Offline
- New Member
- Posts: 3
Thank you for your fast answer.
I've tried to add echo $handle->log but nothing appears... no error and i still can't upload any images...
Do you have an id?
I'm on a french joomla 1.15.20 with K2 2.3
Please Log in or Create an account to join the conversation.
- Nick Texidor
-
- Visitor
The error you mentioned, 'File error. Please try again.' only appears in two places in the upload class. They both appear just after the check to see if a valid file has been passed to the routine. My fixes, previously mentioned, really only apply to the MIME type checking which is done later in the script. So I'm not sure the changes I made are going to help here. I guess the first thing we need to do is work out at which call to the upload class it fails. Could you confirm this happens when you add an image to the K2 item via the back-end? Or is it happening somewhere else? What is the filename you are entering? Does it happen to contain any odd characters, spaces maybe?
It's going to be quite hard to debug this via the forum, so if you'd like a bit of help, then lets take this off to private messages or email, and go from there?
All the best
Nick
Joackim Devaud said:Hello Nick,
Thank you for your fast answer.
I've tried to add echo $handle->log but nothing appears... no error and i still can't upload any images...
Do you have an id?
I'm on a french joomla 1.15.20 with K2 2.3
Please Log in or Create an account to join the conversation.
- Joackim Devaud
-
- Offline
- New Member
- Posts: 3
Please Log in or Create an account to join the conversation.