Jump to content

Recommended Posts

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?

 

Link to comment
https://forums.phpfreaks.com/topic/297180-help-php-rotate-png-image/
Share on other sites

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

 

post-3105-0-23296700-1436132204_thumb.png

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?

:facewall:

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

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.

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...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.