brunch

24. Cloud Function으로 이미지 변환

by Master Seo

<1> 목표

<2> 구성

<3> 실습

<4> 확인하기

<5> 참고

<6> 좋은점



<1> 목표

이미지 변환해 보자



<2> 구성


이미지 --------- Cloud Storage in --------- cloud Function / Cloud Vision---------- Cloud Storage out



<3> 실습


1. 버킷만들기

upload1.serverchk.com

change1.serverchk.com


10 vision.png



2. 변환 소스 다운 로드 하기


1)
git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git


taeho_seo@cloudshell:~ (coastal-burner-254206)$ cd nodejs-docs-samples/


taeho_seo@cloudshell:~/nodejs-docs-samples (coastal-burner-254206)$ cd functions/


taeho_seo@cloudshell:~/nodejs-docs-samples/functions (coastal-burner-254206)$ cd imagemagick/


taeho_seo@cloudshell:~/nodejs-docs-samples/functions/imagemagick (coastal-burner-254206)$ pwd
/home/taeho_seo/nodejs-docs-samples/functions/imagemagick



taeho_seo@cloudshell:~/nodejs-docs-samples/functions/imagemagick (coastal-burner-254206)$ more index.js


// Copyright 2017 Google LLC

// [START functions_imagemagick_setup]const gm = require('gm').subClass({imageMagick: true});const fs = require('fs');const {promisify} = require('util');const path = require('path');const vision = require('@google-cloud/vision');const {Storage} = require('@google-cloud/storage');const storage = new Storage();



2)

형식 :

gcloud functions deploy blurOffensiveImages --runtime nodejs8 --trigger-bucket YOUR_INPUT_BUCKET_NAME --set-env-vars BLURRED_BUCKET_NAME=YOUR_OUTPUT_BUCKET_NAME


실행:

gcloud functions deploy blurOffensiveImages --runtime nodejs8 --trigger-bucket gs://upload1.serverchk.com --set-env-vars BLURRED_BUCKET_NAME=gs://change1.serverchk.com



3. Vision API 사용할수 있도록하기

https://console.developers.google.com/apis/api/vision.googleapis.com/overview?pli=1&project=coastal-burner-254206&folder=&organizationId=


허용하는데 5분 정도 걸립니다.

5분후 확인



4. 이미지 받기

https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git

function > image maging 좀비 이미지


5. 이미지 올려보기




<4> 확인하기


에러 로그 보기

gcloud functions logs read --limit 100




<5> 참고


이미지 change https://cloud.google.com/functions/docs/tutorials/imagemagick?hl=ko


maunal https://linuxer.name/2019/12/gcp-cloud-functions/


기타 github 소스 https://github.com/GoogleCloudPlatform/community/tree/master/tutorials



<6> 좋은점

1. 콘솔로 사용하니 편하다

2. S3 버킷에 대한 권한 등을 따로 주지 않아도 되어 편하다.



감사합니다.

keyword
매거진의 이전글23. Cloud Function  시작해보자