• gm_image - Basic image manipulation
    48 replies, posted
This will let you save/load images to and from files. At the moment it only saves bitmap images, but I'm going to add support for Portable Network Graphics as well. [img_thumb]http://cdbarrett.com/dump/screenshots/garrysmod/gm_flatgrass0036.jpg[/img_thumb] [img_thumb]http://cdbarrett.com/dump/screenshots/garrysmod/gm_flatgrass0037.jpg[/img_thumb] [img_thumb]http://cdbarrett.com/dump/screenshots/garrysmod/gm_flatgrass0035.jpg[/img_thumb] It's not viable to use this in realtime, above as an example, that takes too long to generate to be done in realtime. However, since you can also copy the active rendertarget to an image and save it, you can create your own spawn icons for example. This is a multi-model icon I made and saved to file. [img]http://cdbarrett.com/dump/screenshots/garrysmod/icon.bmp[/img] [b]Functions:[/b] [list] [*]image.CreateImage( width, height ) [*]image.CreateProceduralTexture() [*]Image:GetWidth() [*]Image:GetHeight() [*]Image:CopyRT( x, y, width, height ) [*]Image:Load( filename ) [*]Image:Save( filename ) [*]Image:GetPixel( x, y ) [*]Image:SetPixel( x, y, color ) [/list] [b]Binary:[/b] [url]http://dl.dropbox.com/u/4266088/facepunch/gm_image.zip[/url] [b]Source:[/b] [url]http://dl.dropbox.com/u/4266088/facepunch/gm_image_src.zip[/url] [b]Examples:[/b] [lua]require( "image" ); // capture and save the current image on the screen to file. local screenImage = image.CreateImage( 0, 0 ); screenImage:CopyRT( 0, 0, ScrW(), ScrH() ); screenImage:Save( "./garrysmod/screen.bmp" ); [/lua] [lua]require( "image" ); local gradient = image.CreateImage( 128, 128 ); // write a gradient for x = 0, 127 do for y = 0, 127 do gradient:SetPixel( x, y, Color( ( 255 / 128 ) * i, 0, 0, 255 ) ); end end // commit the image to a texture local texture = image.CreateProceduralTexture(); gradient:Commit( texture ); // draw it surface.SetTexture( texture ); surface.SetDrawColor( 255, 255, 255, 255 ); surface.DrawTexturedRect( 0, 0, 128, 128 );[/lua] [lua]require( "image" ); local icon = image.CreateImage( 0, 0 ); icon:Load( "./garrysmod/icon.bmp" ); // commit the image to a texture local texture = image.CreateProceduralTexture(); icon:Commit( texture ); // draw it surface.SetTexture( texture ); surface.SetDrawColor( 255, 255, 255, 255 ); surface.DrawTexturedRect( 0, 0, 128, 128 );[/lua]
Woah you started this like a few hours ago
Looks awesome. I'll be sure to try it with a wire scanner.
If only this worked server to client... then I could take a picture of their screen and send it to a storage place so admins can look for lua hacks.
Well, you could, but it'd be insanely slow and I wouldn't advise it. The server can read/write bitmap images. The client just has to send the [b]enormous[/b] amount of image data to the server and have it write it. The module is loadable on client and server, it just has extra features on the client.
Very cool Jinto. Would it ever be possible to make it efficient enough to use it in the way Jonney described?
So awesome that you deserve a smiley face.
Would we be able to get a function to create, load and save images to and from a string? I can't remember which program did it, I think it was burning sand or something, but you could generate icons from a length of hexadecimal numbers. Although, I can't think of a good use for it.. More of a novelty thing..
[QUOTE=Kill coDer;14797217]Would we be able to get a function to create, load and save images to and from a string? I can't remember which program did it, I think it was burning sand or something, but you could generate icons from a length of hexadecimal numbers. Although, I can't think of a good use for it.. More of a novelty thing..[/QUOTE] It would make it easier to send the picture of the network.
[QUOTE=Kill coDer;14797217]Would we be able to get a function to create, load and save images to and from a string? I can't remember which program did it, I think it was burning sand or something, but you could generate icons from a length of hexadecimal numbers. Although, I can't think of a good use for it.. More of a novelty thing..[/QUOTE] Just encode the image data to whatever you want, then decode and use SetPixel to write it out.
Well if it was in PNG format, it actually wouldn't be as big but still atleast 512 sends if every send is 255 bytes.
Oh god I love you so much Jinto
Awesome.
Out of curiosity, does this let you save bitmaps with alpha?
god damn, Jinto, amazing work. You always pump out the best modules.
[QUOTE=Levybreak;14822529]Out of curiosity, does this let you save bitmaps with alpha?[/QUOTE] Bitmaps don't support alpha as far as I know. --- This is one of those modules that's cool, but I just can't think of any feasible, reasonable usage for it beyond SetPixel :S in the long run. Any good examples aside from the spawnicon?
Windows Bitmaps do support alpha, although the images themselves aren't that well supported (for example, OS X handles them better than Windows does) The module looks cool, if I ever had any good ideas for things I'd use it.
I'm going to remove bitmap support entirely and switch over to png.
[QUOTE=Jinto;14823910]I'm going to remove bitmap support entirely and switch over to png.[/QUOTE] Will it support animated PNG?
[QUOTE=Levybreak;14841118]Will it support animated PNG?[/QUOTE] Shit is still newer than new. Although animated PNG support would be pretty sweet. The animations of a GIF and the opacity of a PNG.
[QUOTE=Levybreak;14841118]Will it support animated PNG?[/QUOTE] i think a better question is why would it?
[QUOTE=deloc;14856591]i think a better question is why would it?[/QUOTE] Because animated procedural textures = win
sorry for a wee bump, but I have a question, does Image:Load(filename) return the file's binary data? If not (doesn't seem to, looking at the source now. :V) can we have a function that does?
Sorry for the bump, but I still would like to see this being worked on.
PNG loading would be nice...
[QUOTE=Levybreak;17234897]PNG loading would be nice...[/QUOTE] Still waiting for PNG load/save dude :P
[QUOTE=LauIsFun;17728982]Still waiting for PNG load/save dude :P[/QUOTE] Yep. Still waiting for that.
This is really helpful to people who can't make textures like myself. I suppose this doesn't support .psp or .jpg or .img or .png or GIF [b]yet[/b], also is this even being working on anymore?
Yea, I'll rewrite it with some common image formats, probably after the fretta contest is over. Quite busy with that at the moment.
Can't wait to see your input, Jinto.
Sorry, you need to Log In to post a reply to this thread.