<?php
/***************************************************************************

 * Copyright (c) 2015 Baidu.com, Inc. All Rights Reserved
 * 
 **************************************************************************/

$appid = '';
$secKey = ''; 
$salt = '123456789';
$from = 'zh';
$to = 'en';
$cuid = 'APICUID';
$mac = 'MAC';
$imagePath = './123.png';

$sign = md5($appid . md5(file_get_contents($imagePath)) . $salt . $cuid . $mac . $secKey);


$url = 'https://fanyi-api.baidu.com/api/trans/sdk/picture?appid=' . $appid . '&from=' . $from . '&to=' . $to . '&salt=' . $salt . '&cuid=' . $cuid . '&mac=' . $mac . '&sign=' . $sign;
$header = array(
		'Content-Type' => 'multipart/form-data',
	       );
$sendData = array(
		'image' => '@' . realpath($imagePath) . ';type=image/jpeg',
		);
if (class_exists('\CURLFile')) {
	$sendData['image'] = new \CURLFile(realpath($imagePath));
}

$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$sendData);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec($ch);
curl_close($ch);
$callRet = json_decode($result, true);
print_R($result);
