- Posts: 12
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
- Macrohard
-
- Offline
- New Member
Less
More
14 years 2 months ago #70470
by Macrohard
Replied by Macrohard on topic Undesired Feature?? - Transparent PNG's convert to jpg and loose transparency
OK, I got it working, but my transparent PNG's are still not displayed in my RokStories module, even though my cache is generating the png, the module is not referencing it.
Please Log in or Create an account to join the conversation.
- Macrohard
-
- Offline
- New Member
Less
More
- Posts: 12
14 years 2 months ago #70471
by Macrohard
Replied by Macrohard on topic Undesired Feature?? - Transparent PNG's convert to jpg and loose transparency
For those wanting to use Rokstories, there is one final edit to make. From the RT forums:
You need to edit modules/mod_rokstories/helper.php at lines 273 and 274
if (file_exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$id).'_'.$image_size.'.jpg')) {
$image_path = 'media/k2/items/cache/'.md5("Image".$id).'_'.$image_size.'.jpg';
$images->image = JURI::Root(true).'/'.$image_path;
Just change the .jpg to .png.
You need to edit modules/mod_rokstories/helper.php at lines 273 and 274
if (file_exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$id).'_'.$image_size.'.jpg')) {
$image_path = 'media/k2/items/cache/'.md5("Image".$id).'_'.$image_size.'.jpg';
$images->image = JURI::Root(true).'/'.$image_path;
Just change the .jpg to .png.
Please Log in or Create an account to join the conversation.
- Macrohard
-
- Offline
- New Member
Less
More
- Posts: 12
14 years 2 months ago #70472
by Macrohard
Replied by Macrohard on topic Undesired Feature?? - Transparent PNG's convert to jpg and loose transparency
Please Log in or Create an account to join the conversation.
- Jeff Whitmore
-
- Offline
- Junior Member
Less
More
- Posts: 24
14 years 2 months ago #70473
by Jeff Whitmore
Replied by Jeff Whitmore on topic Undesired Feature?? - Transparent PNG's convert to jpg and loose transparency
Seems like an easy enough fix to be added to K2 so we don't have to hack the core. Disappointing that it still hasn't made it in since August 2009 when this thread was started. I just realized the site I'm currently migrating into Joomla/K2 uses png's on all product images and overlays them on differing background images depending on the product category. MVC templating makes it a cinch to create templates with a different background images for the differing categories but the lack of native png uploading to preserve transparency is annoying :( Lol.
Please Log in or Create an account to join the conversation.
- Jeff Whitmore
-
- Offline
- Junior Member
Less
More
- Posts: 24
14 years 2 months ago #70474
by Jeff Whitmore
Replied by Jeff Whitmore on topic Undesired Feature?? - Transparent PNG's convert to jpg and loose transparency
Works on K2 2.5 SVN at least as of last night/today's revision
Please Log in or Create an account to join the conversation.
- Jason Brown
-
- Offline
- New Member
Less
More
- Posts: 14
14 years 2 months ago #70475
by Jason Brown
Replied by Jason Brown on topic Undesired Feature?? - Transparent PNG's convert to jpg and loose transparency
Don't understand what you mean by the last stage. i have followed on a local host install and it seems to be creating a png and a jpg and still picking the converted png.(this is in the cache folder.)
So how do I get it to recognise the png.
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!
So how do I get it to recognise the png.
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.
- Ninja Precision
-
- Offline
- New Member
Less
More
- Posts: 3
14 years 1 month ago #70476
by Ninja Precision
Replied by Ninja Precision on topic Undesired Feature?? - Transparent PNG's convert to jpg and loose transparency
If you're using the K2 content module along with this fix you'll also have to edit the file modules/mod_k2_content/helper.php the same way you edited components/com_k2/models/item.php - this is where the K2 *content module* pulls the image file name from. Adding the if / elseif statements here lets the module choose your transparent PNG.
tim said:
Don't understand what you mean by the last stage. i have followed on a local host install and it seems to be creating a png and a jpg and still picking the converted png.(this is in the cache folder.)
So how do I get it to recognise the png.
tim said:
Don't understand what you mean by the last stage. i have followed on a local host install and it seems to be creating a png and a jpg and still picking the converted png.(this is in the cache folder.)
So how do I get it to recognise the png.
Please Log in or Create an account to join the conversation.
- igZ Magazine
-
- Offline
- New Member
Less
More
- Posts: 4
14 years 4 weeks ago #70477
by igZ Magazine
Replied by igZ Magazine on topic Undesired Feature?? - Transparent PNG's convert to jpg and loose transparency
If you're using the K2 content module along with this fix you'll also have to edit the file modules/mod_k2_content/helper.php the same way you edited components/com_k2/models/item.php - this is where the K2 *content module* pulls the image file name from. Adding the if / elseif statements here lets the module choose your transparent PNG.
i did everything there was above and also ninjas suggestion under 2.4.1 . it doesnt seem to call the png's though. also found a file in administrator/components/com_k2/models called items.php besides the from stephen mentioned item.php .... i wonder if that has something to do with it. tried to apply the same changes to it but it still doesnt work. this is where i start scratching my head what else it could be. please someone give a hint
thx
i did everything there was above and also ninjas suggestion under 2.4.1 . it doesnt seem to call the png's though. also found a file in administrator/components/com_k2/models called items.php besides the from stephen mentioned item.php .... i wonder if that has something to do with it. tried to apply the same changes to it but it still doesnt work. this is where i start scratching my head what else it could be. please someone give a hint
thx
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