django-colorful icon indicating copy to clipboard operation
django-colorful copied to clipboard

return rgb

Open giorg opened this issue 9 years ago • 8 comments
trafficstars

Hi, is it possible to have rgb code instead of hex in return? thanks

giorg avatar Nov 30 '15 11:11 giorg

Hi @giorg, I'm not sure I understand your request. You'd like to store the data as rgb(1,2,3)?

charettes avatar Nov 30 '15 16:11 charettes

Hi, first of all thanks for this cool plugin, it works perfectly. What I need is: when I define in my model

color = RGBColorField(null=True, blank=True)

then when in the admin I choose a color it is saved in my color field as hexadecimal. Is it possible to store it as "45,21,34" for example?

thanks a lot

giorg avatar Nov 30 '15 16:11 giorg

I think it would require some work but It could be possible.

If you're interested on working a patch that adds a kwarg to RGBColorFIeld to opt-in this feature I'd be happy to review it.

charettes avatar Nov 30 '15 16:11 charettes

Is there still interest in making RGB values an option? If so, the best option might be to use a different jQuery color picker.

Looking through the code I found this block. The current picker is converting all RGB values to hex.

A picker like this would provide the option to use many different color formats. The issue would be whether or not changing the color picker could be done in a non-breaking way.

I'd be willing to attempt these changes if there's any interest with such a change?

smarlowucf avatar Jul 02 '16 01:07 smarlowucf

@smarlowucf a patch is welcome but I believe the requested feature was to make the RGBColor database field return a tri-truple instead of a string.

charettes avatar Jul 02 '16 17:07 charettes

Okay, the initial question made me think rgb stored as a string rgb(1,2,3) rather than a tuple (1,2,3).

Migrating to a new jQuery color picker will likely cause some major functionality changes that may be unwanted. The current picker displays a set of colors to be chosen, whereas other pickers I've found provide a palette of colors to choose from. So no input of a colors list would be needed.

Also, CSS expects color formats as strings so sticking to that format seems like an easier option if the color field value is used on the frontend. http://www.w3schools.com/cssref/css_colors_legal.asp

In either case it seems like choosing a JS color picker that supports the wanted color formats is a better option than converting the format on the backend. However, if a color list is wanted the picker I suggested above is not a good option.

smarlowucf avatar Jul 07 '16 21:07 smarlowucf

If someone does undertake this work, please consider offering both RGB and RGBA values (with or without alpha).

shacker avatar Jun 20 '17 19:06 shacker

Possible option.? https://github.com/timchurch/django-color-utils/blob/master/color_utils/utils.py#L4

portedison avatar Feb 11 '19 22:02 portedison