MENU
      Papago Image Translation examples

        Papago Image Translation examples


        Article summary

        The latest service changes have not yet been reflected in this content. We will update the content as soon as possible. Please refer to the Korean version for information on the latest updates.

        Available in Classic and VPC

        This document introduces the Papago Image Translation API examples.

        Image Translation (Text)

        This section describes the Image Translation (Text) API examples.

        Python

        The following is a Python-based sample code for the API.

        import requests
        from requests_toolbelt import MultipartEncoder
        import uuid
        
        data = {
          'source': 'ko',
          'target': 'en',
          'image': ('a.png', open('a.png', 'rb'), 'application/octet-stream', {'Content-Transfer-Encoding': 'binary'})
        }
        m = MultipartEncoder(data, boundary=uuid.uuid4())
        
        headers = {
          "Content-Type": m.content_type,
          "X-NCP-APIGW-API-KEY-ID": user_client_ID,
          "X-NCP-APIGW-API-KEY": user_client_secret
        }
        
        url = "https://naveropenapi.apigw.ntruss.com/image-to-text/v1/translate"
        res = requests.post(url, headers=headers, data=m.to_string())
        print(res.text)
        Python

        Image Translation (Image)

        This section describes the Image Translation (Image) API examples.

        Python

        The following is a Python-based sample code for the API.

        import requests
        from requests_toolbelt import MultipartEncoder
        import uuid
        import json
        import base64
        
        data = {
          'source': 'ko',
          'target': 'en',
          'image': ('a.png', open('a.png', 'rb'), 'application/octet-stream', {'Content-Transfer-Encoding': 'binary'})
        }
        m = MultipartEncoder(data, boundary=uuid.uuid4())
        
        headers = {
          "Content-Type": m.content_type,
          "X-NCP-APIGW-API-KEY-ID": user_client_ID,
          "X-NCP-APIGW-API-KEY": user_client_secret
        }
        
        url = " https://naveropenapi.apigw.ntruss.com/image-to-image/v1/translate"
        res = requests.post(url, headers=headers, data=m.to_string())
        print(res.text)
        
        # renderedImage -> Output as image file
        resObj = json.loads(res.text)
        imageStr = resObj.get("data").get("renderedImage")
        imgdata = base64.b64decode(imageStr)
        
        filename = 'a_translated.png'
        with open(filename, 'wb') as f:
            f.write(imgdata)
        Python

        Was this article helpful?

        Changing your password will log you out immediately. Use the new password to log back in.
        First name must have atleast 2 characters. Numbers and special characters are not allowed.
        Last name must have atleast 1 characters. Numbers and special characters are not allowed.
        Enter a valid email
        Enter a valid password
        Your profile has been successfully updated.