Torrie Posted July 5, 2015 Share Posted July 5, 2015 Hi, this is one of those questions where I would welcome responses like, "why are you doing it THIS way.... this way is better." The software code from a big shipping company sends my server a label image that looks like this: echo '<img src="data:image/png;base64,' . $label_image . '">'; I needed 2 things done: 1.) The image saved 2.) The image displayed rotated. So I thought I'd save it in my label directory, first, with these 2 lines of code: $rawData=base64_decode($label_image); file_put_contents('labels/'. $unique_id . '.png', $rawData); Am I doing at least that part right? It seems to work. I can't get it to rotate, though. And, I don't know if I should rotate it first, before saving.... or, save it as is, and then rotate the displayed image. I could get the image to rotate using CSS.... that's no problem. But it feels like 'cheating' somehow. What's the "real mans way" of rotating? Quote Link to comment https://forums.phpfreaks.com/topic/297180-help-php-rotate-png-image/ Share on other sites More sharing options...
Barand Posted July 5, 2015 Share Posted July 5, 2015 Use PHP GD library and http://php.net/manual/en/function.imagerotate.php Quote Link to comment https://forums.phpfreaks.com/topic/297180-help-php-rotate-png-image/#findComment-1515589 Share on other sites More sharing options...
Torrie Posted July 5, 2015 Author Share Posted July 5, 2015 Already spent a week with the imagerotate, couldn't get it to work. Please suggest some code. Quote Link to comment https://forums.phpfreaks.com/topic/297180-help-php-rotate-png-image/#findComment-1515638 Share on other sites More sharing options...
Barand Posted July 5, 2015 Share Posted July 5, 2015 html <img src='green-up-arrow.png' alt='normal'> <img src='im_rotate.php?fn=green-up-arrow.png' alt='rotated'> im_rotate.php <?php $fn = $_GET['fn']; $im = imagecreatefrompng($fn); $bg = imagecolorat($im, 0,0); $rot = imagerotate($im, 90, $bg); header("Content-type: image/png"); imagepng($rot); imagedestroy($im); imagedestroy($rot); ?> output Quote Link to comment https://forums.phpfreaks.com/topic/297180-help-php-rotate-png-image/#findComment-1515640 Share on other sites More sharing options...
CroNiX Posted July 5, 2015 Share Posted July 5, 2015 You can also rotate an image with just css without resaving it to a new image. Quote Link to comment https://forums.phpfreaks.com/topic/297180-help-php-rotate-png-image/#findComment-1515642 Share on other sites More sharing options...
Torrie Posted July 5, 2015 Author Share Posted July 5, 2015 html <img src='green-up-arrow.png' alt='normal'> <img src='im_rotate.php?fn=green-up-arrow.png' alt='rotated'> im_rotate.php <?php $fn = $_GET['fn']; $im = imagecreatefrompng($fn); $bg = imagecolorat($im, 0,0); $rot = imagerotate($im, 90, $bg); header("Content-type: image/png"); imagepng($rot); imagedestroy($im); imagedestroy($rot); ?> output That's one thing I have trouble with -- the "header" thingy. The code to display the image is half way down my page, header is an html page. <html> <body> Hello, welcome. Here is the image of the wonderful shipping label. Print this page, and then carefully cut around the border and then stick this label on your box. Here is the label for you to trim: <?php echo '<img src="data:image/png;base64,' . $label_image . '">'; ?> Okay and allrighty then, have a great day. </body> </html> ....okay, so in the code above, is it even possible to have PHP rotate that image? Quote Link to comment https://forums.phpfreaks.com/topic/297180-help-php-rotate-png-image/#findComment-1515646 Share on other sites More sharing options...
jcbones Posted July 5, 2015 Share Posted July 5, 2015 Did you read the post that Barand made, and you quoted?He gave you a script, called im_rotate.php, then he gave you TWO different image elements.One image element called the image, the other called the script. Quote Link to comment https://forums.phpfreaks.com/topic/297180-help-php-rotate-png-image/#findComment-1515647 Share on other sites More sharing options...
Barand Posted July 5, 2015 Share Posted July 5, 2015 Quote Link to comment https://forums.phpfreaks.com/topic/297180-help-php-rotate-png-image/#findComment-1515650 Share on other sites More sharing options...
Torrie Posted July 6, 2015 Author Share Posted July 6, 2015 Aww, isn't that cute! How you found a little yellow man banging his head against the wall. Like, that is 'you' and, that's how you feel some times. I just want to cuddle you and rub you behind the ears. Okay, dumbass dip-dorks, first of all, hey JACKASS CRONIX did you even READ My post? NO CSS! Jerk. And, now, This "Barand" person. What RUDE LAND are you from? Were you born a rude worm? Or did TWO UGLY PIMPLE-FACED PERL NEWSGROUP GEEKS FROM THE 90'S go bump uglies in your grandma's toilet-closet and create you? I'll go with that one (it matches the picture I have of you in my head). SECOND OF ALL, you have "HEADER" in your damn code. That means I can NOT HAVE IT IN THE MIDDLE of my html like I am ASKING FOR.... got it?!? Or are you too busy categorizing your "LET'S FIND EMOJIS TO PUT DOWN NEWBIE PHP PEOPLE." GOD DAMN! You must be the webmaster, anybody with any sense would have banned a rude jackass as yourself. YOUR CODE DON'T WORK! Why does it not work? Because you did NOT read my post. You don't know what I want, and, after seeing your replies to OTHER PEOPLE, I notice you have a .... shall we say "pattern" of being rude to just about everybody that asks questions. Please for the LOVE OF GOD BAN ME. MY php questions are so far and few between that I actually FORGET that this is the ASSHOLE forum, and I end up stupidly posting here. Give your butt-ugly wife a kiss for me. BYE Quote Link to comment https://forums.phpfreaks.com/topic/297180-help-php-rotate-png-image/#findComment-1515669 Share on other sites More sharing options...
scootstah Posted July 6, 2015 Share Posted July 6, 2015 SECOND OF ALL, you have "HEADER" in your damn code. That means I can NOT HAVE IT IN THE MIDDLE of my html like I am ASKING FOR.... got it?!? Had you actually bothered to read the code that Barand posted, you would probably realize that there is no header() in the middle of the HTML. You are simply using a PHP script as an image, with a simple <img/> tag. Perhaps you should read your own post - considering it does not say anywhere that you can not use this approach. Nor does it say you can't use CSS - in fact you even pointed out that you could use CSS. You're either a massive idiot, or just another worthless troll. Quote Link to comment https://forums.phpfreaks.com/topic/297180-help-php-rotate-png-image/#findComment-1515670 Share on other sites More sharing options...
CroNiX Posted July 6, 2015 Share Posted July 6, 2015 Geez, someone having a hissy-fit meltdown? Over coding help? I hope you can get over it and enjoy life a bit. You seem pretty miserable to blow up like that when people are just trying to HELP you. And yes, I did read your post and no, you didn't say "no css". I won't call you names though... Quote Link to comment https://forums.phpfreaks.com/topic/297180-help-php-rotate-png-image/#findComment-1515725 Share on other sites More sharing options...
jcbones Posted July 6, 2015 Share Posted July 6, 2015 I'm voting a no ban. I love to see people blow up because they can't follow directions. Quote Link to comment https://forums.phpfreaks.com/topic/297180-help-php-rotate-png-image/#findComment-1515728 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.