1. 分词服务(包装了知识库)
2. 通用布局服务(text, pos, angle, size, color)
3. 图片生成库
4. 前端应用
代码部署方案:
分词服务、微博内容服务都需要部署到sae平台上。
布局服务、图片生成则可以灵活处理。
1. 分词服务(包装了知识库)
class TextSegment
{
/**
* add $text to segmented service
*/
public function add($text);
/**
* get segmented terms
* @return array()
*/
public function get();
}
2. 通用布局服务(text, pos, angle, size, color)
classTextLayout
{
/**
* add $text to the layout
*/
publicfunction add($text);
/**
* get segmented terms
* @return array({x, y, size, angle, color})
*/
public function get();
}
<?php
///
/// segment_service.php
///
$texts = split_into_small_packet($_REQUEST['postdata']);
$text_segment = new TextSegment();
foreach($texts as $text)
{
$text_segment.add($text);
}
echo $text_segment.get();
?>
<?
///
/// layout_service.php
///
$words =split_word($_REQUEST['postdata']);
$layout = new Textlayout();
foreach($words as $word)
{
$layout.add($word);
}
echo $layout.get();
?>
3. 图片生成库
classTextCanvas
{
/**
* add $text to the canvas
*/
publicfunction add($text);
/**
* get image
* @return a PNG stream
*/
public function get();
/**
* get image
* @return a PNG file url
*/
public function save();
}
<?
///
/// image_service.php
///
$words =decode_words_info($_REQUEST['postdata']);
$canvas= new TextCanvas();
foreach($words as $word)
{
$canvas.add($word);
}
$img_path = $canvas.save();
echo $img_path;
?>
<?
///
/// service_cgi.php
///
/// @note: 下面的函数,可以通过直接引用类的方式实现,也可以通过rpc的方式实现
$weibo_id = $_REQUEST["weibo_id"];
$texts = my_get_user_timeline($weibo_id);
$segs = my_get_word_segment($texts);
$words = my_get_word_layout($segs);
$url = my_get_image($words);
echo $url;
?>
4. 前端应用
<script>
$data = GetAllMyText();
ajax segment_service($data);
ajax layout_service($data);
postdata = data;
ajax.json_post("postdata");
</script>
<script>
ajax.json_post("service_cgi.php?id=weibo_id" function(data){
img.src = data.addr;
});
</script>