- Posts: 130
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
- Bryan Smith
- Topic Author
- Offline
- Premium Member
Less
More
15 years 1 month ago #70450
by Bryan Smith
Undesired Feature?? - Transparent PNG's convert to jpg and loose transparency was created by Bryan Smith
Took me a bit to figure out what was going on here.
If you upload a PNG with transparency for the main item image it get's converted into a JPG and arbitrarily masks to white. Looses it's transparency in all resolutions, (I'm assuming).
This is a bit of a bummer. I was about to build a gallery of public art that had all clipped images for the main item image.
Anyone know if it's possible to choose a different file format for main image conversions.
An alternative might be to manually edit the tables and upload the PNG versions of the files to the same folder. (not a fun prospect because the filenames get rewritten in the process too.
If you upload a PNG with transparency for the main item image it get's converted into a JPG and arbitrarily masks to white. Looses it's transparency in all resolutions, (I'm assuming).
This is a bit of a bummer. I was about to build a gallery of public art that had all clipped images for the main item image.
Anyone know if it's possible to choose a different file format for main image conversions.
An alternative might be to manually edit the tables and upload the PNG versions of the files to the same folder. (not a fun prospect because the filenames get rewritten in the process too.
Please Log in or Create an account to join the conversation.
- Anna Lindgren
- Offline
- New Member
Less
More
- Posts: 2
14 years 9 months ago #70451
by Anna Lindgren
Replied by Anna Lindgren on topic Undesired Feature?? - Transparent PNG's convert to jpg and loose transparency
I am also having this issue, anyone solved this?
Please Log in or Create an account to join the conversation.
- David S. Greenberg
- Offline
- New Member
Less
More
- Posts: 2
14 years 6 months ago #70452
by David S. Greenberg
Replied by David S. Greenberg on topic Undesired Feature?? - Transparent PNG's convert to jpg and loose transparency
The problem is that when the images are getting uploaded, they are being converted to the JPEG format, and when converted to that, the upload class has a default image back ground color of white. JPEG doesn't support transparency, so this is why all your transparent PNG's are getting uploaded with a white background.
This is a big PITA in my book. If I wanted the things converted, I'd convert them. I really hate that this on-the-fly, didn't-ask-for-it conversion is taking place. Yeah, yeah, I know all about the fact that IE does a lousy job of displaying PNG's - maybe I dont' care, maybe I wanted it that way - regardless, the software took away that choice from me.
That said, I need my client's site to work now, and I've got too many K2 items created to rip it all out and go with something else. My client has a foreground color of light gray (#f5f5f5), and all the graphics I'm uploading started out as transparent PNG's so what I did to compensate for the software's forced conversion was to modify this file:
administrator/components/com_k2/models/item.php
Search for "upload" - you'll quickly see the spots where the various image sizes are created. You'll see where the conversion happens too (all those $handle->image_convert = 'png'; statements).
Just add a line below the statements that create each particular image size which specifies a background color. In my case, I used this:
$handle->image_background_color = '#f5f5f5';
Then when the photos got uploaded, the background color of the image was set to what I was using for the foreground color on the website, and everything blended in nicely.
Yes, I did try changing the $handle->image_convert = 'jpg'; to just '' and 'png' - took out the piece that set the image quality for the jpeg too, no effect. There was some code just below the uploading that created the cache copies and appended a '.jpg' to the cache filename. Because I'm short on time, I didn't feel like fooling around with the code to append whatever the extension was of the uploaded filename.
Maybe someone else will and will upload a patch so this forced, unwanted image conversion will come to an end.
Besides this annoyance, I really like K2 - just getting beaten up by my client, so I'm pissy right now...
This is a big PITA in my book. If I wanted the things converted, I'd convert them. I really hate that this on-the-fly, didn't-ask-for-it conversion is taking place. Yeah, yeah, I know all about the fact that IE does a lousy job of displaying PNG's - maybe I dont' care, maybe I wanted it that way - regardless, the software took away that choice from me.
That said, I need my client's site to work now, and I've got too many K2 items created to rip it all out and go with something else. My client has a foreground color of light gray (#f5f5f5), and all the graphics I'm uploading started out as transparent PNG's so what I did to compensate for the software's forced conversion was to modify this file:
administrator/components/com_k2/models/item.php
Search for "upload" - you'll quickly see the spots where the various image sizes are created. You'll see where the conversion happens too (all those $handle->image_convert = 'png'; statements).
Just add a line below the statements that create each particular image size which specifies a background color. In my case, I used this:
$handle->image_background_color = '#f5f5f5';
Then when the photos got uploaded, the background color of the image was set to what I was using for the foreground color on the website, and everything blended in nicely.
Yes, I did try changing the $handle->image_convert = 'jpg'; to just '' and 'png' - took out the piece that set the image quality for the jpeg too, no effect. There was some code just below the uploading that created the cache copies and appended a '.jpg' to the cache filename. Because I'm short on time, I didn't feel like fooling around with the code to append whatever the extension was of the uploaded filename.
Maybe someone else will and will upload a patch so this forced, unwanted image conversion will come to an end.
Besides this annoyance, I really like K2 - just getting beaten up by my client, so I'm pissy right now...
Please Log in or Create an account to join the conversation.
- David S. Greenberg
- Offline
- New Member
Less
More
- Posts: 2
14 years 6 months ago #70453
by David S. Greenberg
Replied by David S. Greenberg on topic Undesired Feature?? - Transparent PNG's convert to jpg and loose transparency
Hit send too quick... The lines are around Line 165 in the file, and the renaming for the cache copies are around line 308
Please Log in or Create an account to join the conversation.
- juro
- Offline
- Senior Member
Less
More
- Posts: 42
14 years 5 months ago #70454
by juro
Replied by juro on topic Undesired Feature?? - Transparent PNG's convert to jpg and loose transparency
Yes, this is a bummer!
In my version of K2 (2.2), this function is in
/administrator/components/com_k2/lib/class.upload.php ... line 3338
Interestingly, in line 981 there is a variable called $image_convert, where it seems that one can change the filetype and it actually states that "Default value is '' (no conversion)", which isn't true. Maybe whoever wrote the class or whatever could comment?
Even more interestingly, changing ANYTHING in this file is totally disregarded, so this class might not even be used?
In my version of K2 (2.2), this function is in
/administrator/components/com_k2/lib/class.upload.php ... line 3338
Interestingly, in line 981 there is a variable called $image_convert, where it seems that one can change the filetype and it actually states that "Default value is '' (no conversion)", which isn't true. Maybe whoever wrote the class or whatever could comment?
Even more interestingly, changing ANYTHING in this file is totally disregarded, so this class might not even be used?
Please Log in or Create an account to join the conversation.
- juro
- Offline
- Senior Member
Less
More
- Posts: 42
14 years 5 months ago #70455
by juro
Replied by juro on topic Undesired Feature?? - Transparent PNG's convert to jpg and loose transparency
Ok, next update.
In /administrator/components/com_k2/models/item.php from line 181
Here the above mentioned classes attributes (namely image_convert) is set for every image and image size. If you comment out this line for every image (original, XLarge through XSmall)
$handle->image_convert = 'jpg';
The file will be saved in the original format.
Now my problem is that K2 is trying to access the *.jpg when accessing $this->item->image in the template but this is (obviously) null, so the image is not displayed ... any ideas?
In /administrator/components/com_k2/models/item.php from line 181
Here the above mentioned classes attributes (namely image_convert) is set for every image and image size. If you comment out this line for every image (original, XLarge through XSmall)
$handle->image_convert = 'jpg';
The file will be saved in the original format.
Now my problem is that K2 is trying to access the *.jpg when accessing $this->item->image in the template but this is (obviously) null, so the image is not displayed ... any ideas?
Please Log in or Create an account to join the conversation.
- juro
- Offline
- Senior Member
Less
More
- Posts: 42
14 years 5 months ago #70456
by juro
Replied by juro on topic Undesired Feature?? - Transparent PNG's convert to jpg and loose transparency
After delving into the code, I have found out that K2 does not store the actual file names of the images. What it does is create a md5 using the item's id and then append both the size ('_XS', '_L', etc) and '.jpg' to the end. So in the current version there is no possibility of storing the image types of seperate items.
I am pretty sure that I can manhandle the system so that it uses pngs exclusively, but it would be great to see the possibility of at least keeping the original in the original format or - even better - save the file type for later reference.
I am pretty sure that I can manhandle the system so that it uses pngs exclusively, but it would be great to see the possibility of at least keeping the original in the original format or - even better - save the file type for later reference.
Please Log in or Create an account to join the conversation.
- Simon Wells
- Offline
- Platinum Member
Less
More
- Posts: 955
14 years 5 months ago #70457
by Simon Wells
Replied by Simon Wells on topic Undesired Feature?? - Transparent PNG's convert to jpg and loose transparency
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
Simon
K2 Support
Please Log in or Create an account to join the conversation.
- DownloadVerifier
- Offline
- New Member
Less
More
- Posts: 1
14 years 4 months ago #70458
by DownloadVerifier
Replied by DownloadVerifier on topic Undesired Feature?? - Transparent PNG's convert to jpg and loose transparency
Thanks David,
Your solution worked perfectly, let's just hope this will be sorted out in the next release, on a side note, love K2, keep up the good work.
Your solution worked perfectly, let's just hope this will be sorted out in the next release, on a side note, love K2, keep up the good work.
Please Log in or Create an account to join the conversation.
- juro
- Offline
- Senior Member
Less
More
- Posts: 42
14 years 2 months ago #70459
by juro
Replied by juro on topic Undesired Feature?? - Transparent PNG's convert to jpg and loose transparency
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
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
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