Add support for image optimization

未关闭
#61 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
30/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
java
领域
api

调研方向

首先检查 Java SDK 的结构,以及与相应 image-optimization helper 相关的已链接 .NET SDK pull request。将此 issue 中的参数规范作为行为检查清单,并为每种受支持的转换和每个无效输入情况添加覆盖,然后确认生成的 URL 与预期结果一致。

由索引模型根据 Issue 内容生成。

描述

groomed hacktoberfest help wanted up-for-grabs

Kentico Cloud now supports image optimization. It gives developers the option of transforming images using URL parameters. The goal of this task is to implement a helper class that will make generation of image URLs easy for the developers.

The reference code can be observed in the .NET SDK.

The full specification follows:

Example

Scale
image.jpg?mode=scale&width=300
image.jpg?mode=scale&height=150
image.jpg?mode=fit&height=150&width=300

DPR
image.jpg?mode=scale&width=300&dpr=2.0

Specification

If a developer provides a parameter with invalid value or omits a parameter that is required for desired optimization, the Asset API will either ignore this parameter, or return the original asset without any optimizations.

Also, to keep our sanity, we will transform each image optimization parameter independently from others. Yes, this approach might sometimes produce surprising results. However, both Fastly and imgix are designed to handle a set of parameters that do not make sense and we are not making the situation worse.

Regarding requests to the Asset API, the idea is to go through all parameters, transform the supported ones and get rid of everything else.

To get a grasp of the image optimization You can experiment with two identical images:

rect=x,y,w,h (incompatible with crop)

- -
x is not float Nothing
x < 0.0 Nothing
y is not float Nothing
y < 0.0 Nothing
w is not float Nothing
w <= 0.0 Nothing
h is not float Nothing
h <= 0.0 Nothing
h <= 0.0 Nothing
otherwise crop={w},{h},x{x},y{y}

If the rect parameter is malformed, just ignore it.

fit=crop&crop=focalpoint&fp-x=x&fp-y=y&fp-z=z (incompatible with rect)

- -
x is not float set x as 0.5
y is not float set y as 0.5
z is not float Nothing
z <= 1.0 Nothing
1 / z < 1.0 Nothing
otherwise crop={1 / z},{1 / z},offset-x{(x * z - 0.5) / (z - 1)},offset-y{(y * z - 0.5) / (z - 1) * 100}

Both offset-x and offset-y must be clamped into range from 0 to 100.

imgix supports crop by both rectangle and focal point. Unfortunately, it is not so easy to calculate Fastly parameters. Therefore, let's declare the rect parameter more important. So, if both crop by rectangle and focal point are specified, choose the first.

fm=x

- -
x = gif format=gif
x = png format=png
x = png8 format=png8
x = jpg format=jpg
x = pjpg format=pjpg
x = webp format=webp
otherwise Nothing

fm=webp&lossless=x

- -
x = 1 format=webpll
x = true format=webpll
x = 0 format=webply
x = false format=webply
otherwise format=webp

q=x

- -
x is not float Nothing
otherwise quality={x}\

auto=x

- -
x = format auto=webp
otherwise Nothing

Local variables and related functions will be required to transform parameters.

主要语言
Java
星标
17
派生
27
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

kontent-ai/java-packages 的其他 Issue

查看 kontent-ai/java-packages 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。