Skip to content

Commit

Permalink
Update rthk.py
Browse files Browse the repository at this point in the history
  • Loading branch information
raileo98 authored Oct 25, 2024
1 parent b92ec08 commit dc2a908
Showing 1 changed file with 0 additions and 16 deletions.
16 changes: 0 additions & 16 deletions code/rthk.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,6 @@ async def optimize_image_quality(imgUrl):
latest_imgUrl = modify_image_url(imgUrl, 1)
latestAvailableQ = None

has_matched_condition = False

while True:
imgUrlWithQ = modify_image_url(imgUrl, q)

Expand Down Expand Up @@ -451,9 +449,6 @@ async def optimize_image_quality(imgUrl):

if q <= 95:
q = max(1, q - 5) # 確保 q 不會低於 1

if content_length > upstream_response_length:
has_matched_condition = True # 設置為 True

elif content_length < 1000 * 100:
logging.info(f'[INFO] 圖片大小小於 500KB - imageUrl: {imgUrl} - 當前質量參數 q: {q}')
Expand All @@ -466,17 +461,6 @@ async def optimize_image_quality(imgUrl):
latest_imgUrl = latestAvailableQ if latestAvailableQ else imgUrlWithQ
break

# 在迴圈結束後檢查是否滿足過條件,並額外減少 q
if has_matched_condition and (upstream_response_length < 1000 * 100 or content_length_q99 < 1000 * 100):
if q == 99:
q = 95

if q <= 95:
q = max(1, q - 5) # 確保 q 不會低於 1

# 更新 latest_imgUrl 以反映最終的 q 值
latest_imgUrl = modify_image_url(imgUrl, q)

return latest_imgUrl

def modify_image_url(imageUrl, new_quality):
Expand Down

0 comments on commit dc2a908

Please sign in to comment.