發表文章

目前顯示的是 7月, 2022的文章

Ubuntu上複製相片的exif資訊(導出&導入)

安裝套件 sudo apt install exiv2 顯示相片資訊 exiv2 pr IMG2022.jpg 導出相片資訊 exiv2 ex IMG2022.jpg 會產生相同檔名的.exv檔案,以上面指令來說就是產生 IMG2022.exv 若有縮圖還會產生縮圖檔,以上面指令來說就是產生 IMG2022-thumb.jpg 導入相片資訊 exiv2 in IMG2022.jpg 會抓去當下目錄同明得.exv和-thumb.jpg檔案(不見得有)去覆蓋相片資訊

筆記:HTML5 canvas畫圖

  畫線 const ctx = canvasEle . getContext ( " 2d " ); ctx . strokeStyle = color; ctx . lineWidth = width; ctx . beginPath (); ctx . moveTo (x, y); ctx . lineTo (x1, y1); ctx . stroke (); ctx . closePath (); 畫矩形 const ctx = canvasEle . getContext ( " 2d " ); ctx . strokeStyle = color; ctx . lineWidth = width; ctx . strokeRect (x, y, w, h); 畫橢圓 const ctx = canvasEle . getContext ( " 2d " ); ctx . strokeStyle = color; ctx . lineWidth = width; ctx . beginPath (); const wrad = w / 2.0 , hrad = h / 2.0 ; ctx . ellipse (x + wrad, y + hrad, wrad, hrad, rotate, 0 , 2 * Math.PI); ctx . stroke (); ctx . closePath (); 畫字 參考:  https://stackoverflow.com/questions/14836350/ const ctx = canvasEle . getContext ( " 2d " ); ctx . font = ` ${ fontStyle } ${ size } px ${ fontFace } ` ; const metrics = ctx . measureText (text); ctx . fillStyle = color; // 讓文字位

js陣列應用筆記

有感於一陣子沒碰js就會忘記陣列操作方法,這裡再次筆記複習一下 找陣列中的元素 indexOf,lastIndexOf,和find,findIndex以及includes都可以找元素,不同點在於找元素的方法與回傳的值不同 indexOf是給予元素值,回傳第一個吻合的元素所在位置,若-1就是找不到吻合的元素 selectedIds . indexOf ( obj . id ) === - 1 lastIndexOf就是反過來找而已。 這裡要注意的就是indexOf和lastIndexOf是用===來判斷是否吻合元素,所以如果你是要判斷物件就需要用到find.findIndex find是給予一個函數,用來找第一個吻合的元素本身;若null就是找不到吻合的元素 const selected = steps. find ((s) => id === s . id ); findIndex跟find參數一樣,只是回傳吻合元素的所在位置 includes是給予元素值,用來確認元素是否在陣列中 selectedIds . includes ( s . id ) 新增元素 增加元素到陣列後方 有push和concat兩種選擇, 前者是加入原本的陣列,後者是產生新的陣列 selectedIds . concat ( obj . id ) 然後我也滿常偷懶像下面這樣做 []. concat ( obj . id ) [obj.id] 以前寫C習慣則是都會寫下面這樣 let array = null ; if (null === array ) array = []; array . concat ( obj . id ); 關於哪些陣列方法是回傳新陣列,哪些是修改舊有的可以看由tsuifei所整理的" JS 從陣列 Array 尾端新增元素的 push() "中的圖片一覽無遺。 更新元素 可以用forEach,map,reduce去遍歷元素 forEach是對原本的陣列處理 map是更新元素並產生新陣列 const updated = origin . map ((o) => o . setOffset (x, y)); reduce則是可以在遍歷時增加/減少元素,簡單來說就是forEach,map都可以用redu

解決Ubuntu 20.04在apt update的cloud-cli更新錯誤

圖片
最近一次手動下Ubuntu的apt update更新時發現有一行錯誤 E: The repository 'https://packages.cloud.google.com/apt cloud-cli Release' does not have a Release file. 往前追溯還會有404 Not found的錯誤 Err:15 https://packages.cloud.google.com/apt cloud-cli Release    404  Not Found [IP: 172.217.163.46 443]