http.Post for render.Capture?

Hey! I am making screenshot system for gmod.

  1. Can i send render.Capture data to webserver?
  2. If i can, how i would do it using http.Post?

You can convert the image to a “string” and send it over.
On the webserver you’d have to find some language like php to handle the saving.

There are public and free addons that do this.

And how do i convert it to string, so that php could decode it?

render.Capture returns a string, you might also want to use

util.Compress and then decompress it on the webserver, but that’s not essential

render.Capture already outputs a string.

Wait wait. I writed it to file and there was strange icons/things in the file. Does that count as string??

A string can be used to represent any binary data. http.Post ( or your webserver ) may not support specific characters such as null characters. Try using util.Base64Encode on your data before sending it and on your webserver decode that.

Yeah, Base64 is good. How do i post it? I dont get the tutorial and it is without example…



http.Post( "http://example.com/", { data = util.Base64Encode( my_data ) } )


You’d access the data on your website as the “data” parameter of the post data. In php that’d be $_POST[‘data’].


<?php 
$data = $_POST['data'];

$imageData = base64_decode($data);
$source = imagecreatefromstring($data);
$rotate = imagerotate($source, 0, 0); // if want to rotate the image
$imageSave = imagejpeg($rotate, "test", 100);
imagedestroy($source);

?>

This didn’t work…
Error:


[15-Feb-2015 07:23:32 UTC] PHP Warning:  imagecreatefromstring(): Empty string or invalid image in screenshot.php on line 5
[15-Feb-2015 07:23:32 UTC] PHP Warning:  imagerotate() expects parameter 1 to be resource, boolean given in on line 6
[15-Feb-2015 07:23:32 UTC] PHP Warning:  imagejpeg() expects parameter 1 to be resource, boolean given in screenshot.php on line 7
[15-Feb-2015 07:23:32 UTC] PHP Warning:  imagedestroy() expects parameter 1 to be resource, boolean given in screenshot.php on line 8

And my lua code:



function sendScreenshot()
	local RCD = { }

	RCD.format = "jpeg"
	RCD.h = ScrH()
	RCD.w = ScrW()
	RCD.quality = 100 //100 is max quality, but 70 is good enough.
	RCD.x = 0
	RCD.y = 0

	local Picdata = render.Capture(RCD)
	
	http.Post( "http://futuretechs.eu/screenshot/screenshot.php", { data = util.Base64Encode( Picdata ) } )
	
	print("Sent")
end

Calling the sendScreenshot() manually.



$imageData = base64_decode($data);
$source = imagecreatefromstring($data);


You did it wrong.

I don’t see difference, i may be dumb…

I didn’t change it. Fix your own crap :v:

Lol, alright i realized that. Still the same problem, changed $data to $imageData

[editline]15th February 2015[/editline]

Well, i dont get it tried 5 examples and all says that the string may be null?

[editline]15th February 2015[/editline]

Rewriting time then, i will send it to player.

Any way to open the Picdata at client? I mean like browser, expect it opens the text file as jpeg?