我正在电子商务网站上在线购买 iphone 手机壳,客户可以上传和自定义图像。
因此,在 magento 管理面板中,我将该产品图像转换为 jpg 并保存。但是我想在打印时在图像下方显示订单号,以便在打印的图像中我可以打印带有订单号的图像。
我的 jQuery 代码是:
jQuery.post('https://'+window.location.hostname+'/artmanager/index/pngtojpg',{imagedata:img}).done(
function(data)
{
jimg=data;
window.open(data);
jQuery("#loading-image").hide();
});
我的控制器代码是:
public function pngtojpgAction()
{
//Code to convert png to jpg image
$input = imagecreatefrompng($this->getRequest()->getParam('imagedata'));
$width=imagesx($input);
$height=imagesy($input);
$output = imagecreatetruecolor($width, $height);
$white = imagecolorallocate($output, 255, 255, 255);
imagefilledrectangle($output, 0, 0, $width, $height, $white);
imagecopy($output, $input, 0, 0, 0, 0, $width, $height);
$mypath=Mage::getBaseDir('media').'/custom_product_preview/predefined_images/temporary_processing/test.jpg' ;//Saving file as temporary file
imagejpeg($output,$mypath,100);
$filename = $mypath; //Reading the temporary file
// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = 3056;
$newheight = 4861;
// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
ob_start();
imagejpeg($thumb);
$contents = ob_get_contents();
$contents = substr_replace($contents, pack("cnn", 1, 72, 72), 13, 5); //Converting Image DPI to 72DPI
ob_end_clean();
echo 'data:image/jpeg;base64,'.base64_encode($contents);
}