Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jsk_robot_startup] Support embed image in email_topic.py #1485

Merged

Conversation

tkmtnt7000
Copy link
Member

@tkmtnt7000 tkmtnt7000 commented May 24, 2022

This PR supports sending embed image with email_topic.py. (Discussion in #1463)


TODO

  • Set image size

  • sample code
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import rospy
import time
from jsk_robot_startup.msg import Email
from jsk_robot_startup.msg import EmailBody

def main():
    rospy.init_node('embed_image_test')
    pub = rospy.Publisher("email", Email, queue_size=10)

    msg = Email()
    content_1 = EmailBody()
    content_1.type = 'text'
    content_1.message = 'こんにちは.\n'
    content_2 = EmailBody()
    content_2.type = 'img'
    content_2.file_path = '/home/tsukamoto/Pictures/spotkinova_attachment.jpg'
    content_4 = EmailBody()
    content_4.type = 'img'
    content_4.file_path = '/home/tsukamoto/Pictures/boston_template.png'
    content_5 = EmailBody()
    content_5.type = 'text'
    content_5.message = '\n 今日はSpotで遊んだよ\n'
    content_6 = EmailBody()
    content_6.type = 'img'
    content_6.file_path = '/home/tsukamoto/Pictures/fetch-door4.png'
    content_7 = EmailBody()
    content_7.type = 'text'
    content_7.message = '\n Fetchにも手伝ってもらったよ.\n'
    content_8 = EmailBody()
    content_8.type = 'text'
    content_8.message = '\n'

    msg.body = [content_1, content_2, content_8, content_4, content_5, content_6, content_7]
    msg.subject = 'embed_test'
    msg.sender_address = '[email protected]'
    msg.receiver_address = '[email protected]'
    print (msg)

    time.sleep(1)
    rospy.loginfo("Publish")
    pub.publish(msg)

main()

@tkmtnt7000 tkmtnt7000 changed the title [WIP] [jsk_robot_startup] Support embed image in email_topic.py [jsk_robot_startup] Support embed image in email_topic.py May 24, 2022
@knorth55
Copy link
Member

Superb!
In example code, where do you add the first and second image?

@tkmtnt7000
Copy link
Member Author

In example code, where do you add the first and second image?

Sorry, I mistakenly write an example code. Updated.

@708yamaguchi
Copy link
Member

708yamaguchi commented May 24, 2022

Thank you for this cool feature!

I also checked that html type worked well.

    content_1 = EmailBody()
    content_1.type = 'html'
    content_1.message = '<p><font size="7" color="#00ff00">サイズが7で緑色</font></p>\n'

One thing.
Do we need to use \n like below?
If possible, I do not want to write \n in the message field. (Maybe my original code is bad, sorry)

    content_5.message = '\n 今日はSpotで遊んだよ\n'

@708yamaguchi
Copy link
Member

One thing.
Do we need to use \n like below?
If possible, I do not want to write \n in the message field. (Maybe my original code is bad, sorry)

    content_5.message = '\n 今日はSpotで遊んだよ\n'

Sorry, \n is needed when we want to write multiple line message.

@tkmtnt7000 tkmtnt7000 force-pushed the PR-support-embed-image-master branch from 26eba36 to 9cd94a0 Compare May 25, 2022 05:50
@tkmtnt7000
Copy link
Member Author

tkmtnt7000 commented May 25, 2022

Thank you for comments.
The size of embedded images can now be specified as a percentage.

content = EmailBody()
content.type = 'img'
content.file_path = '/home/tsukamoto/Pictures/fetch-door4.png'
content.img_size = 50 

Now, we have to write \n manually as a text type when multiple images are to be aligned vertically.
It is possible to automatically break each image into a new line, but I feel that there is a demand to arrange images horizontally...

Copy link
Member

@k-okada k-okada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!!
I am OK with this. just to confirm no one will spend time, just to move this code to another in future...

c.f. jsk-ros-pkg/jsk_common#1607

@knorth55
Copy link
Member

the release is a good point of jsk_common, hmm.
currently if jaxon wants to send e-mail, they need to install jsk_robot, which is a bit unfriendly.
I'm for to move this node to jsk_common.

@k-okada
Copy link
Member

k-okada commented May 25, 2022

I understand your thoughts, specially I found jsk_robot_startup/EmailBody line.
But Jaxon robot should depend on jsk_robot_startup and uses life log to store sensor/event data and use them to learn something from experiments….

@tkmtnt7000
Copy link
Member Author

So... should I move email_topic.py to https://github.com/jsk-ros-pkg/jsk_common ???

@knorth55
Copy link
Member

But Jaxon robot should depend on jsk_robot_startup and uses life log to store sensor/event data and use them to learn something from experiments….

I agree.
I think both idea is acceptable, so its better to leave it in jsk_robot now.

@tkmtnt7000
Copy link
Member Author

tkmtnt7000 commented May 26, 2022

OK.
I'll make PR to jsk_common to leave it in jsk_robot now.

@tkmtnt7000
Copy link
Member Author

tkmtnt7000 commented May 26, 2022

Sorry, I understood mistakenly.
I leave this node in jsk_robot and do not move to jsk_common.

Copy link
Member

@Affonso-Gui Affonso-Gui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arguably it would also be nice to have an option to send an image directly from the client, instead of needing a local path in the robot PC. (I and Kochigami are working on a similar case for Pepper's tablet, thinking of further usage with scratch)

The message could be encoded as base64 or any other ros-compliant data type.
e.g.

[app_manager/Icon]:
string format
uint8[] data

We should evaluate if this is safe or not first, though.

@tkmtnt7000
Copy link
Member Author

When I was writing a node that sends an email with an image depending on the state of smach, I realized that it would be nice to receive the image topic(sensor_msgs/Image) directly.
k-okada#60

@k-okada k-okada merged commit f8365f6 into jsk-ros-pkg:master Aug 9, 2022
@tkmtnt7000 tkmtnt7000 deleted the PR-support-embed-image-master branch June 6, 2023 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants