9 posts
Posted 10 December 2015 - 03:22 AM
So I have made a system using Peripherals++ that uses the ME Bridge and sends all items in an ME system to a PHP script that inputs that data into a database so I can display it on a website.
What I want to try and figure out if it's possible to somehow get the textures of items from the game to a php script and then save to a web server to use when displaying the list of items.
I found this post:
http://www.computerc...rver-using-php/Which makes me feel like it's possible as long as I can get the textures but I have no clue how to convert an image to base64 with CC.
If anybody can help me out it would be extremely appreciated.
Thanks, Mura.
Edited on 10 December 2015 - 02:36 AM
1080 posts
Location
In the Matrix
Posted 10 December 2015 - 03:42 AM
I don't think CC can GET the image files for items.
9 posts
Posted 10 December 2015 - 03:44 AM
I don't think CC can GET the image files for items.
Yeah I highly doubted it could. My question was more on the topic of if I found a way to do so, how would I get those images from where they are stored, to a web server.
Thanks for the input though.
7083 posts
Location
Tasmania (AU)
Posted 10 December 2015 - 05:28 AM
Why not upload the image data directly to the server on which you stored the php script? Is there any particular reason you would want the php script to try and handle it?
To my limited understanding, the game generates the inventory icons (which I'm assuming are what you're actually wanting) for most blocks "on the fly", based on their textures. ComputerCraft computers don't have access to these icons nor to the textures, not unless you manually stick them onto their drives.
9 posts
Posted 10 December 2015 - 05:32 AM
Why not upload the image data directly to the server on which you stored the php script? Is there any particular reason you would want the php script to try and handle it?
To my limited understanding, the game generates the inventory icons (which I'm assuming are what you're actually wanting) for most blocks "on the fly", based on their textures. ComputerCraft computers don't have access to these icons nor to the textures, not unless you manually stick them onto their drives.
I probably didn't explain my question very well, but sending the image data to a PHP script is what I want to do. The reason I dont want to upload all of the images to the server is because that would take a very long time for all of the mods I play with. If I had a system that did it automatically then it wouldn't matter what mods I installed.
Lets assume I found a way to save the texture for an item to the current computer's ID file folder, how would I convert that into a base64 string?
Thanks for your time btw.
Edited on 10 December 2015 - 04:37 AM
7083 posts
Location
Tasmania (AU)
Posted 10 December 2015 - 05:47 AM
Well, the "really simple" way would be to let my
Package script do it. If you're simply using it at the command line it applies some compression that your php script will probably have trouble dealing with, but if you instead load it up as an API then you can do this sort of thing:
os.loadAPI("package")
local base64VersionOfFile = package.toBase64( fs.open("someimagefile.png", "rb") )
You can then use the
HTTP API to send that off where ever.
I'm not entirely sure how many image files you'd get onto a ComputerCraft computer before maxing out its drive capacity (about a megabyte, by default).
9 posts
Posted 10 December 2015 - 05:55 AM
Wow, thanks so much for all that information and help!
About maxing out its drive capacity: Would that be the case if the images were stored at saves/[world]/computer/[id]/ ?
Again, thanks for helping me out!
7083 posts
Location
Tasmania (AU)
Posted 10 December 2015 - 06:24 AM
About maxing out its drive capacity: Would that be the case if the images were stored at saves/[world]/computer/[id]/ ?
Yes, each such ID folder may only contain an amount of bytes up to whatever ComputerCraft.cfg is configured to permit per system.
If you exceed that, then the computer with that ID will fail on any attempts to open files for write access. It'll be able to read files just fine, though.
9 posts
Posted 10 December 2015 - 06:53 AM
Yes, each such ID folder may only contain an amount of bytes up to whatever ComputerCraft.cfg is configured to permit per system.
If you exceed that, then the computer with that ID will fail on any attempts to open files for write access. It'll be able to read files just fine, though.
Sorry to bother you, but it seems when I create an image from the base64 string using php from the CC computer, the image is corrupt. However if I take that exact same image and upload it to a image to base64 site to get a string, the image works fine.
os.loadAPI("package")
local base64VersionOfFile = package.toBase64( fs.open("test.png", "rb") )
local req = http.post("url here", "str="..textutils.urlEncode(base64VersionOfFile))
print(req.readAll())
Edited on 10 December 2015 - 05:54 AM
7083 posts
Location
Tasmania (AU)
Posted 10 December 2015 - 07:25 AM
Hrm. I can certainly look into it later this evening, but some examples would make that easier - as would the URLs for the other converter(s) you're using.
9 posts
Posted 10 December 2015 - 07:43 AM
7083 posts
Location
Tasmania (AU)
Posted 11 December 2015 - 12:17 AM
I've updated the package paste with a new version which I guess'll sort things out.
That's what I get for only testing my encoder using my own decoder… silly of me. :(/>
9 posts
Posted 11 December 2015 - 01:43 AM
Can confirm it now works!, thanks very much Bomb Bloke!