2020年9月24日 星期四

[開發進程] Image Processor

總結一下Image Processor的製作流程:

  1. 想出如何實現用戶需求
  2. 依據需求編制程序
  3. 優化所寫程序
  4. 錯誤處理
  5. 系統整體優化


例子: [用戶需求] 在模版中把文字貼在shop banner上

由不知道->知道 (User requirement)

嘗試找出用什麼技術可以實現用戶需求


開始編制 (Development)

一步步實現用戶需求、由UI Frontend到Backend, 或由Backend到UI Frontend皆可, 一步步擴充功能, 再進一步優化logic, 來來回回

例如: 使用php function imagettftext()能把需求實現; 用OO比function為佳; 先以jpeg為試驗, 和以少量text-font選擇作為測試, 再擴充功能


錯誤處理 (Error Handling)

處理報錯, 但不要用die

(因为die的意思是程序终止,如果合成banner失败,我的任务不应该影响客户的操作(sync up, listing, verify ebay items),而且die()也不会返回错误消息,网页就是一片空白,queue job也显示中断退出。这样会给客户造成很大的困惑。)

  • 可以用 return ['result' => false, 'error_message' => '...']; 返回, 再使用 log file 記錄錯誤
  • 可以在不同地方用 isset 檢查資料是否正常存在
  • 其他處理方式, 例如在我的case, 若果error就返回用原來的圖片加文字分開的方式顯示


程序及資源優化 (Optimization)

試試整個流程用法, 想想在什麼地方可以更優化系統

例如在我的case, 把圖片 url save 到 datasheet 可以把功能實現, 卻浪費資源; 假如把圖片 url save 到 template 比 save 到 datasheet 為佳, 因為可以重覆使用, 減少 generate 時間, 和圖片伺服器資源

又例如原本設計是 template 有修改, 圖片連結就會重新記錄, 因為有機會改動 shop banner 的一些參數; 但日常很少機會修改template shop banner, 所以系統修改成更改 template 時如沒有修改與 shop banner 有關的fields, 就會保留圖片連結

=====================

Commit list:

  1. UI 加入 shop_banner_stick_text_to_image option (User requirement)
  2. 加入genTextedImage function (support jpeg only) (support 3 google fonts only) 
    use php function imagettftext() to put text on top of image (Development) 
  3. 加入所有text font files (Development) 
  4. save to datasheet extra data (Development) 
  5. 加入genTextedImage (support jpeg & png) (Development) 
  6. move logic to HTImageProcessor (Development) 
  7. don't use die, use return for error handling (Error Handling)
  8. store texted shop banner to template instead of datasheet (Optimization)
  9. error handling when generate error (return result = false) (Error Handling)
  10. 加入genTextedImage (support jpeg, png & gif) (User requirement)
  11. error handling (Error Handling)
  12. revised image output image size logic (User requirement)
  13. move HTImageProcessor to Helper folder (Development)
  14. change text font file relative path (Development)
  15. make font path array compatible when sync up template (Development)
  16. image processing error enhancement (Error Handling)
  17. image processing error enhancement (if error , fall back to original text + image display; write error to template designer error log) (Error Handling)
  18. error handling for cdncloud upload error (use isset($cdnurl[$realfilename]['url']) ) (Error Handling)
  19. error handling check (use isset($data['shop_banner_url'][$shop_idx]) ) (Error Handling)
  20. added [Template Designer]: retain shop_banner_url if shop banner-related fields do not change; else clear to generate text-combined image next time  (Optimization)

沒有留言:

張貼留言

[康復路] 試完又試

見了醫生,因為血色素又變低了,醫生想檢查是否「缺鐵」為成因,檢查又檢查…… 感覺有些麻煩……又抽血,又要留樣本…… 令我回想起當日入院的時光,因為一些原因,留樣本只需留一次,免卻留三次的麻煩;現在每天都要留一次,連續三天。每天早上就要跑醫院一趟再上班。 幸好也完成了。 第二次抽血...