Dynamically filter images in Drupal 7

自古美人都是妖i 提交于 2021-01-29 18:12:13

问题


I am trying to build a custom module in Drupal 7 that allows a user to upload an image and apply a filter. In particular, I am trying to adjust the contrast. The user can adjust the contrast via an HTML slidecontainer which will adjust the CSS contrast on the image. On submit the contrast value will be sent to the server, and applied to the image via the imagefilter() function in the GD library.

My problem is that I cannot replicate the resulting CSS filter with the imagefilter() method in the GD library.

I adjust the CSS contrast values to scale with the GD contrast values, but the images still do not match. For example, the scale for the CSS contrast function is:

  • completely grey: 0%
  • no change: 100%
  • more contrast: +100%

and the scale for GD is:

  • completely grey: 100
  • no change: 0
  • max contrast: -100

Hence, GD Contrast = (CSS Contrast - 100) * -1.

Here are example photos with CSS/PHP contrast values of 25/75:

and 175/-75:

I'm open to other suggestions, such as if this is not really possible I can rethink the UI, or if there is a way to reference and present another module to the user within a custom module. However, I would like to be able to change the contrast adjustment function from CSS to GD to more accurately reflect user changes in the front end.

I have not tried this with other values, such as brightness, but it seems to not be an issue per this SO question.

Here are a few other similar and unanswered SO questions regarding sepia as well as brightness.

来源:https://stackoverflow.com/questions/64188292/dynamically-filter-images-in-drupal-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!