I was recently implementing UPS API for PHP.
I found those two great sources from Gabriel Bull or simple one from Alex Fraundhof.
When I ask to get the shipping Label by
$Response = $ShipperObj->createLabel($params);
the result is label that is rotated by 90 degrees to the right.
I didn’t found any parameter to get the label rotated as I want.
Following code will rotate the label back. The source of the labe is in base64 and so the result of my function:
$image=imagecreatefromgif('data://text/plain;base64,'.$label['label_image']);
if ($image) {
$image=imagerotate($image, 270, 0);
if ($image===FALSE) {
$imageBase64=$label['label_image'];
} else {
ob_start();
imagegif($image);
$imageBase64=base64_encode(ob_get_contents());
ob_end_clean();
}
} else {
$imageBase64=$label['label_image'];
NOTE: imagecreatefromgif with the text parameters requires allow_url_fopen to be on. If you have it off, you need to convert the base64 manually and then open the image as binary.


Leave a Reply