- Posts: 2
COMMUNITY FORUM
- Forum
- K2 Community Forum
- English K2 Community
- Undesired Feature?? - Transparent PNG's convert to jpg and loose transparency
Undesired Feature?? - Transparent PNG's convert to jpg and loose transparency
- Chris Salvato
- Offline
- New Member
Less
More
13 years 7 months ago #70460
by Chris Salvato
Replied by Chris Salvato on topic Undesired Feature?? - Transparent PNG's convert to jpg and loose transparency
Roland Jungwirth said:Hi Simon, is there any way to see when this will be implemented?
Roland
Simon Wells (K2 Support) said:I have seen this first hand and it is a pain, so I have added this to a our list of requested features for K2 for the core team. Simon
K2 Support
Any update? I have K2 2.3 and there is no workaround. I wanted to put the article images in a table that alternates row colors from Gray to white but now I am unable to do that because my images change to jpgs. This is very annoying.
Let me know when you are planning to do this. If not soon, then I will have to change the design of the site :(
Roland
Simon Wells (K2 Support) said:I have seen this first hand and it is a pain, so I have added this to a our list of requested features for K2 for the core team. Simon
K2 Support
Any update? I have K2 2.3 and there is no workaround. I wanted to put the article images in a table that alternates row colors from Gray to white but now I am unable to do that because my images change to jpgs. This is very annoying.
Let me know when you are planning to do this. If not soon, then I will have to change the design of the site :(
Please Log in or Create an account to join the conversation.
- Stephen Austin
- Offline
- New Member
Less
More
- Posts: 3
13 years 7 months ago #70461
by Stephen Austin
Replied by Stephen Austin on topic Undesired Feature?? - Transparent PNG's convert to jpg and loose transparency
I've got a solution for this. its not super sexy, but it works.
in /components/com_k2/models/item.php replace the if chain starting on line 110 with:
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XS.png'))
$item->imageXSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XS.png';
else if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XS.jpg'))
$item->imageXSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XS.jpg';
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_S.png'))
$item->imageSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_S.png';
else if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_S.jpg'))
$item->imageSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_S.jpg';
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_M.png'))
$item->imageMedium = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_M.png';
else if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_M.jpg'))
$item->imageMedium = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_M.jpg';
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_L.png'))
$item->imageLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_L.png';
else if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_L.jpg'))
$item->imageLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_L.jpg';
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XL.png'))
$item->imageXLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XL.png';
else if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XL.jpg'))
$item->imageXLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XL.jpg';
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_Generic.png'))
$item->imageGeneric = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_Generic.png';
else if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_Generic.jpg'))
$item->imageGeneric = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_Generic.jpg';
In /administrator/components/com_k2/models/item.php insert this after the Generic image processing section line ~295:
/////////////////////PNG
//Original image
$savepath = JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'src';
$handle->image_convert = 'png';
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = md5("Image".$row->id);
$handle->Process($savepath);
$filename = $handle->file_dst_name_body;
$savepath = JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache';
//XLarge image
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'png';
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = $filename.'_XL';
if (JRequest::getInt('itemImageXL')) {
$imageWidth = JRequest::getInt('itemImageXL');
} else {
$imageWidth = $params->get('itemImageXL', '800');
}
$handle->image_x = $imageWidth;
$handle->Process($savepath);
//Large image
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'png';
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = $filename.'_L';
if (JRequest::getInt('itemImageL')) {
$imageWidth = JRequest::getInt('itemImageL');
} else {
$imageWidth = $params->get('itemImageL', '600');
}
$handle->image_x = $imageWidth;
$handle->Process($savepath);
//Medium image
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'png';
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = $filename.'_M';
if (JRequest::getInt('itemImageM')) {
$imageWidth = JRequest::getInt('itemImageM');
} else {
$imageWidth = $params->get('itemImageM', '400');
}
$handle->image_x = $imageWidth;
$handle->Process($savepath);
//Small image
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'png';
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = $filename.'_S';
if (JRequest::getInt('itemImageS')) {
$imageWidth = JRequest::getInt('itemImageS');
} else {
$imageWidth = $params->get('itemImageS', '200');
}
$handle->image_x = $imageWidth;
$handle->Process($savepath);
//XSmall image
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'png';
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = $filename.'_XS';
if (JRequest::getInt('itemImageXS')) {
$imageWidth = JRequest::getInt('itemImageXS');
} else {
$imageWidth = $params->get('itemImageXS', '100');
}
$handle->image_x = $imageWidth;
$handle->Process($savepath);
//Generic image
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'png';
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = $filename.'_Generic';
$imageWidth = $params->get('itemImageGeneric', '300');
$handle->image_x = $imageWidth;
$handle->Process($savepath);
Finally, wherever you are using an image from the k2 item, replace the .jpg extension with .png (if you need transparancy).
In short, technique writes an additional set of png (alpha intact) to the cache directory, and makes them available to the application via the same name as the jpg counterpart. No existing functionality should be broken by this since it is an additive change. I'll post a more thorough blog about this at some point.
One final note, if you need to implement the png version, a simple string replace looks something like this:
I'm a c# guy, not really php, and being as lazy as I am, I'm not going to look up how to do a proper substring trim... just dont name your image blah.png.png.png....
Good Luck!
in /components/com_k2/models/item.php replace the if chain starting on line 110 with:
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XS.png'))
$item->imageXSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XS.png';
else if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XS.jpg'))
$item->imageXSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XS.jpg';
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_S.png'))
$item->imageSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_S.png';
else if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_S.jpg'))
$item->imageSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_S.jpg';
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_M.png'))
$item->imageMedium = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_M.png';
else if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_M.jpg'))
$item->imageMedium = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_M.jpg';
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_L.png'))
$item->imageLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_L.png';
else if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_L.jpg'))
$item->imageLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_L.jpg';
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XL.png'))
$item->imageXLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XL.png';
else if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XL.jpg'))
$item->imageXLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XL.jpg';
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_Generic.png'))
$item->imageGeneric = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_Generic.png';
else if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_Generic.jpg'))
$item->imageGeneric = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_Generic.jpg';
In /administrator/components/com_k2/models/item.php insert this after the Generic image processing section line ~295:
/////////////////////PNG
//Original image
$savepath = JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'src';
$handle->image_convert = 'png';
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = md5("Image".$row->id);
$handle->Process($savepath);
$filename = $handle->file_dst_name_body;
$savepath = JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache';
//XLarge image
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'png';
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = $filename.'_XL';
if (JRequest::getInt('itemImageXL')) {
$imageWidth = JRequest::getInt('itemImageXL');
} else {
$imageWidth = $params->get('itemImageXL', '800');
}
$handle->image_x = $imageWidth;
$handle->Process($savepath);
//Large image
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'png';
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = $filename.'_L';
if (JRequest::getInt('itemImageL')) {
$imageWidth = JRequest::getInt('itemImageL');
} else {
$imageWidth = $params->get('itemImageL', '600');
}
$handle->image_x = $imageWidth;
$handle->Process($savepath);
//Medium image
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'png';
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = $filename.'_M';
if (JRequest::getInt('itemImageM')) {
$imageWidth = JRequest::getInt('itemImageM');
} else {
$imageWidth = $params->get('itemImageM', '400');
}
$handle->image_x = $imageWidth;
$handle->Process($savepath);
//Small image
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'png';
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = $filename.'_S';
if (JRequest::getInt('itemImageS')) {
$imageWidth = JRequest::getInt('itemImageS');
} else {
$imageWidth = $params->get('itemImageS', '200');
}
$handle->image_x = $imageWidth;
$handle->Process($savepath);
//XSmall image
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'png';
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = $filename.'_XS';
if (JRequest::getInt('itemImageXS')) {
$imageWidth = JRequest::getInt('itemImageXS');
} else {
$imageWidth = $params->get('itemImageXS', '100');
}
$handle->image_x = $imageWidth;
$handle->Process($savepath);
//Generic image
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'png';
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = $filename.'_Generic';
$imageWidth = $params->get('itemImageGeneric', '300');
$handle->image_x = $imageWidth;
$handle->Process($savepath);
Finally, wherever you are using an image from the k2 item, replace the .jpg extension with .png (if you need transparancy).
In short, technique writes an additional set of png (alpha intact) to the cache directory, and makes them available to the application via the same name as the jpg counterpart. No existing functionality should be broken by this since it is an additive change. I'll post a more thorough blog about this at some point.
One final note, if you need to implement the png version, a simple string replace looks something like this:
I'm a c# guy, not really php, and being as lazy as I am, I'm not going to look up how to do a proper substring trim... just dont name your image blah.png.png.png....
Good Luck!
Please Log in or Create an account to join the conversation.
- j37h3r
- Offline
- New Member
Less
More
- Posts: 4
13 years 5 months ago #70462
by j37h3r
Replied by j37h3r on topic Undesired Feature?? - Transparent PNG's convert to jpg and loose transparency
This really needs to be adapted for 2.4.1 already!
Please Log in or Create an account to join the conversation.
- j37h3r
- Offline
- New Member
Less
More
- Posts: 4
13 years 5 months ago #70463
by j37h3r
Replied by j37h3r on topic Undesired Feature?? - Transparent PNG's convert to jpg and loose transparency
Also to Stephen: Is this fix something that will work for new images to uploaded, besides existing images.
We have been holding off uploading images until a fix has been worked. Thanks for your support!
We have been holding off uploading images until a fix has been worked. Thanks for your support!
Please Log in or Create an account to join the conversation.
- Jiliko.net
- Offline
- Platinum Member
Less
More
- Posts: 567
13 years 5 months ago #70464
by Jiliko.net
Replied by Jiliko.net on topic Undesired Feature?? - Transparent PNG's convert to jpg and loose transparency
Hi guys,
The bad news is that seems not to be corrected in 2.5 SVN
Olivier
The bad news is that seems not to be corrected in 2.5 SVN
Olivier
Please Log in or Create an account to join the conversation.
- Stephen Austin
- Offline
- New Member
Less
More
- Posts: 3
13 years 5 months ago #70465
by Stephen Austin
Replied by Stephen Austin on topic Undesired Feature?? - Transparent PNG's convert to jpg and loose transparency
It should work for any image, but I haven't tested that specifically.
j37h3r said:Also to Stephen: Is this fix something that will work for new images to uploaded, besides existing images.
We have been holding off uploading images until a fix has been worked. Thanks for your support!
j37h3r said:Also to Stephen: Is this fix something that will work for new images to uploaded, besides existing images.
We have been holding off uploading images until a fix has been worked. Thanks for your support!
Please Log in or Create an account to join the conversation.
- j37h3r
- Offline
- New Member
Less
More
- Posts: 4
13 years 5 months ago #70466
by j37h3r
Replied by j37h3r on topic Undesired Feature?? - Transparent PNG's convert to jpg and loose transparency
Actually it works brilliantly moving forward, your mention of the application towards existing images was very helpful.
Also, tested this with 2.4.1, works without issue.
Stephen Austin said:It should work for any image, but I haven't tested that specifically.
j37h3r said:Also to Stephen: Is this fix something that will work for new images to uploaded, besides existing images. We have been holding off uploading images until a fix has been worked. Thanks for your support!
Also, tested this with 2.4.1, works without issue.
Stephen Austin said:It should work for any image, but I haven't tested that specifically.
j37h3r said:Also to Stephen: Is this fix something that will work for new images to uploaded, besides existing images. We have been holding off uploading images until a fix has been worked. Thanks for your support!
Please Log in or Create an account to join the conversation.
- Stephen Austin
- Offline
- New Member
Less
More
- Posts: 3
13 years 5 months ago #70467
by Stephen Austin
Replied by Stephen Austin on topic Undesired Feature?? - Transparent PNG's convert to jpg and loose transparency
Great, glad to help.
j37h3r said:Actually it works brilliantly moving forward, your mention of the application towards existing images was very helpful.
Also, tested this with 2.4.1, works without issue.
Stephen Austin said:It should work for any image, but I haven't tested that specifically.
j37h3r said:Also to Stephen: Is this fix something that will work for new images to uploaded, besides existing images. We have been holding off uploading images until a fix has been worked. Thanks for your support!
j37h3r said:Actually it works brilliantly moving forward, your mention of the application towards existing images was very helpful.
Also, tested this with 2.4.1, works without issue.
Stephen Austin said:It should work for any image, but I haven't tested that specifically.
j37h3r said:Also to Stephen: Is this fix something that will work for new images to uploaded, besides existing images. We have been holding off uploading images until a fix has been worked. Thanks for your support!
Please Log in or Create an account to join the conversation.
- Macrohard
- Offline
- New Member
Less
More
- Posts: 12
13 years 3 months ago #70468
by Macrohard
Replied by Macrohard on topic Undesired Feature?? - Transparent PNG's convert to jpg and loose transparency
I'm using K2 2.4.1, and having major issues with this. I am trying to publish a Rokstories module, and can't get transparency working because of this. I've tried all the mentioned edits to no avail, and rebuilt my image cache, but they are still caching as .jpg. I don't see any of the referenced "$handle->image_convert" in the item.php file at all, anywhere. Does someone have the edited files that will work with the latest version?
Please Log in or Create an account to join the conversation.
- Macrohard
- Offline
- New Member
Less
More
- Posts: 12
13 years 3 months ago #70469
by Macrohard
Replied by Macrohard on topic Undesired Feature?? - Transparent PNG's convert to jpg and loose transparency
I'm not seeing Generic image processing around line 295? Running K2 2.4.1.
Stephen Austin said:
I've got a solution for this. its not super sexy, but it works.
in /components/com_k2/models/item.php replace the if chain starting on line 110 with:
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XS.png'))
$item->imageXSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XS.png';
else if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XS.jpg'))
$item->imageXSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XS.jpg';
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_S.png'))
$item->imageSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_S.png';
else if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_S.jpg'))
$item->imageSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_S.jpg';
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_M.png'))
$item->imageMedium = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_M.png';
else if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_M.jpg'))
$item->imageMedium = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_M.jpg';
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_L.png'))
$item->imageLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_L.png';
else if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_L.jpg'))
$item->imageLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_L.jpg';
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XL.png'))
$item->imageXLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XL.png';
else if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XL.jpg'))
$item->imageXLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XL.jpg';
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_Generic.png'))
$item->imageGeneric = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_Generic.png';
else if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_Generic.jpg'))
$item->imageGeneric = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_Generic.jpg';
In /administrator/components/com_k2/models/item.php insert this after the Generic image processing section line ~295:
/////////////////////PNG
//Original image
$savepath = JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'src';
$handle->image_convert = 'png';
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = md5("Image".$row->id);
$handle->Process($savepath);
$filename = $handle->file_dst_name_body;
$savepath = JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache';
//XLarge image
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'png';
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = $filename.'_XL';
if (JRequest::getInt('itemImageXL')) {
$imageWidth = JRequest::getInt('itemImageXL');
} else {
$imageWidth = $params->get('itemImageXL', '800');
}
$handle->image_x = $imageWidth;
$handle->Process($savepath);
//Large image
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'png';
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = $filename.'_L';
if (JRequest::getInt('itemImageL')) {
$imageWidth = JRequest::getInt('itemImageL');
} else {
$imageWidth = $params->get('itemImageL', '600');
}
$handle->image_x = $imageWidth;
$handle->Process($savepath);
//Medium image
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'png';
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = $filename.'_M';
if (JRequest::getInt('itemImageM')) {
$imageWidth = JRequest::getInt('itemImageM');
} else {
$imageWidth = $params->get('itemImageM', '400');
}
$handle->image_x = $imageWidth;
$handle->Process($savepath);
//Small image
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'png';
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = $filename.'_S';
if (JRequest::getInt('itemImageS')) {
$imageWidth = JRequest::getInt('itemImageS');
} else {
$imageWidth = $params->get('itemImageS', '200');
}
$handle->image_x = $imageWidth;
$handle->Process($savepath);
//XSmall image
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'png';
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = $filename.'_XS';
if (JRequest::getInt('itemImageXS')) {
$imageWidth = JRequest::getInt('itemImageXS');
} else {
$imageWidth = $params->get('itemImageXS', '100');
}
$handle->image_x = $imageWidth;
$handle->Process($savepath);
//Generic image
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'png';
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = $filename.'_Generic';
$imageWidth = $params->get('itemImageGeneric', '300');
$handle->image_x = $imageWidth;
$handle->Process($savepath);
Finally, wherever you are using an image from the k2 item, replace the .jpg extension with .png (if you need transparancy).
In short, technique writes an additional set of png (alpha intact) to the cache directory, and makes them available to the application via the same name as the jpg counterpart. No existing functionality should be broken by this since it is an additive change. I'll post a more thorough blog about this at some point.
One final note, if you need to implement the png version, a simple string replace looks something like this:
I'm a c# guy, not really php, and being as lazy as I am, I'm not going to look up how to do a proper substring trim... just dont name your image blah.png.png.png....
Good Luck!
Stephen Austin said:
I've got a solution for this. its not super sexy, but it works.
in /components/com_k2/models/item.php replace the if chain starting on line 110 with:
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XS.png'))
$item->imageXSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XS.png';
else if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XS.jpg'))
$item->imageXSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XS.jpg';
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_S.png'))
$item->imageSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_S.png';
else if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_S.jpg'))
$item->imageSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_S.jpg';
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_M.png'))
$item->imageMedium = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_M.png';
else if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_M.jpg'))
$item->imageMedium = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_M.jpg';
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_L.png'))
$item->imageLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_L.png';
else if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_L.jpg'))
$item->imageLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_L.jpg';
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XL.png'))
$item->imageXLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XL.png';
else if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XL.jpg'))
$item->imageXLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XL.jpg';
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_Generic.png'))
$item->imageGeneric = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_Generic.png';
else if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_Generic.jpg'))
$item->imageGeneric = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_Generic.jpg';
In /administrator/components/com_k2/models/item.php insert this after the Generic image processing section line ~295:
/////////////////////PNG
//Original image
$savepath = JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'src';
$handle->image_convert = 'png';
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = md5("Image".$row->id);
$handle->Process($savepath);
$filename = $handle->file_dst_name_body;
$savepath = JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache';
//XLarge image
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'png';
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = $filename.'_XL';
if (JRequest::getInt('itemImageXL')) {
$imageWidth = JRequest::getInt('itemImageXL');
} else {
$imageWidth = $params->get('itemImageXL', '800');
}
$handle->image_x = $imageWidth;
$handle->Process($savepath);
//Large image
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'png';
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = $filename.'_L';
if (JRequest::getInt('itemImageL')) {
$imageWidth = JRequest::getInt('itemImageL');
} else {
$imageWidth = $params->get('itemImageL', '600');
}
$handle->image_x = $imageWidth;
$handle->Process($savepath);
//Medium image
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'png';
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = $filename.'_M';
if (JRequest::getInt('itemImageM')) {
$imageWidth = JRequest::getInt('itemImageM');
} else {
$imageWidth = $params->get('itemImageM', '400');
}
$handle->image_x = $imageWidth;
$handle->Process($savepath);
//Small image
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'png';
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = $filename.'_S';
if (JRequest::getInt('itemImageS')) {
$imageWidth = JRequest::getInt('itemImageS');
} else {
$imageWidth = $params->get('itemImageS', '200');
}
$handle->image_x = $imageWidth;
$handle->Process($savepath);
//XSmall image
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'png';
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = $filename.'_XS';
if (JRequest::getInt('itemImageXS')) {
$imageWidth = JRequest::getInt('itemImageXS');
} else {
$imageWidth = $params->get('itemImageXS', '100');
}
$handle->image_x = $imageWidth;
$handle->Process($savepath);
//Generic image
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'png';
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = $filename.'_Generic';
$imageWidth = $params->get('itemImageGeneric', '300');
$handle->image_x = $imageWidth;
$handle->Process($savepath);
Finally, wherever you are using an image from the k2 item, replace the .jpg extension with .png (if you need transparancy).
In short, technique writes an additional set of png (alpha intact) to the cache directory, and makes them available to the application via the same name as the jpg counterpart. No existing functionality should be broken by this since it is an additive change. I'll post a more thorough blog about this at some point.
One final note, if you need to implement the png version, a simple string replace looks something like this:
I'm a c# guy, not really php, and being as lazy as I am, I'm not going to look up how to do a proper substring trim... just dont name your image blah.png.png.png....
Good Luck!
Please Log in or Create an account to join the conversation.
- Forum
- K2 Community Forum
- English K2 Community
- Undesired Feature?? - Transparent PNG's convert to jpg and loose transparency