SRL Archive - Other Scripts

Launch of PictureToDatabase & PicturefromDatabase for scripters!


ShowerThoughts

2009-05-08 22:47:37

Hey, scripters!
Tootoot222 and me created a PictureDatabase script.
It uses PHP for connection to the database.

You have to fill in 2 cons, then you can put your picture in the database.

const
Name = 'Example';
Path = 'C:\Picture.bmp';
One line to add it to the database.

AddPToDatabase(Name, Width, height, BMPString: string);
Note: you need a small procedure to perform ^.

The script can add it and get it and preview the picture.
In your script your probably only need the GetPFromDatabase function.

Which works like this:

var
BMP: integer;
BMP := GetPFromDatabase('PictureName');//Name.
Note: you need a small function to perform ^.

[ScreenShot of the script in action ^^.]

Scar Add and Get Script + Preview.

program New;
var
W, H, BMP: Integer;
const
Name = 'Flag2';//My P0wnage flag
Path = 'C:\Afbeeldingen\B.bmp';//Path to picture.
CheckWorking = true;//Preview if true.
procedure AddPToDatabase(Name, Width, height, BMPString: string);//Adds the BMP.
var
HTTPClient: Integer;
Code:string;
begin
Writeln(Length(BMPString));
HTTPClient := InitializeHTTPClient(False, False);
AddPostVariable(HTTPClient, 'Name', Name);
AddPostVariable(HTTPClient, 'Width', Width);
AddPostVariable(HTTPClient, 'Height', Height);
AddPostVariable(HTTPClient, 'BMPString', BMPString);
Code := PostHTTPPageEx(HTTPClient, 'http://server01.impsoft.info/IN.php');
Writeln(Code);
end;
function GetPFromDatabase(Name: string): integer;//Gets the BMP.
var
HTTPClient, P: Integer;
Code, D: String;
A :array of string;
begin
HTTPClient := InitializeHTTPClient(False, False);
AddPostVariable(HTTPClient, 'Name', Name);
Code := PostHTTPPageEx(HTTPClient, 'http://server01.impsoft.info/OUT.php');
A:= Explode(#10, Code);
if StartsWith('GOOD', A[0]) then
begin
P:= Pos(':', A[1]);
W := StrToIntDef(Trim(Copy(A[1], P + 1, Length(A[1]) - P)), 0);
P:= Pos(':', A[2]);
H := StrToIntDef(Trim(Copy(A[2], P + 1, Length(A[2]) - P)), 0);
P:= Pos(':', A[3]);
D := Trim(Copy(A[3], Pos(':', A[3]) + 1, Length(A[3]) - P));
Result := BitmapFromString(W, H, D);
Exit;
end;
end;

procedure PreviewPicture;
var
Bmp: Integer;
begin
Bmp:= GetPFromDatabase(Name);//Gets
DisplayDebugImgWindow(W, H);
SafeCopyCanvas(GetBitmapCanvas(Bmp), GetDebugCanvas, 0, 0, W, H, 0, 0, W, H);
end;

begin
if (not (Path = '')) then
begin
BMP := LoadBitmap(Path);
GetBitmapSize(BMP, W, H);
AddPToDatabase(Name, IntToStr(W), IntToStr(H), BitmapToString(BMP));//Adds
FreeBitmap(BMP);
end;
if CheckWorking then PreviewPicture;//Preview
writeln('DONE!');
end.

The Get Function.
Add this to your script for the getting part(few lines).

function GetPFromDatabase(Name: string): integer;//Gets the BMP.
var
HTTPClient, P: Integer;
Code, D: String;
A :array of string;
begin
HTTPClient := InitializeHTTPClient(False, False);
AddPostVariable(HTTPClient, 'Name', Name);
Code := PostHTTPPageEx(HTTPClient, 'http://server01.impsoft.info/OUT.php');
A:= Explode(#10, Code);
if StartsWith('GOOD', A[0]) then
begin
P:= Pos(':', A[1]);
W := StrToIntDef(Trim(Copy(A[1], P + 1, Length(A[1]) - P)), 0);
P:= Pos(':', A[2]);
H := StrToIntDef(Trim(Copy(A[2], P + 1, Length(A[2]) - P)), 0);
P:= Pos(':', A[3]);
D := Trim(Copy(A[3], Pos(':', A[3]) + 1, Length(A[3]) - P));
Result := BitmapFromString(W, H, D);
Exit;
end;
end;

Note:
We don't need credits. Since this is not so spectacular.
The only thing you have to do is adding the get function to your script,
fill in the Name:string; parameter.

We hope you enjoy it!

~Hermen & Tootoot222

Harry

2009-05-08 22:48:43

Convert the images to .png so your server space does not get raped by 16 MB .bmp images. (err, or ""bitmap strings")

Other than that, nice work.

ShowerThoughts

2009-05-08 22:51:31

They need good graphics.
HQ, needed for nice forms.
I will "offer" HQ since people should use it :).
It will not in any way decrease the quality; AFAIK.

Thanks, for feedback.

Freddy1990

2009-05-08 23:55:22

From: Hermen
They need good graphics.
HQ, needed for nice forms.
I will "offer" HQ since people should use it :).
It will not in any way decrease the quality; AFAIK.

Thanks, for feedback.


Erm… PNG uses lossless compression… It doesn't decrease the image quality at all…

ShowerThoughts

2009-05-09 00:37:27

From: Freddy1990
Erm… PNG uses lossless compression… It doesn't decrease the image quality at all…

Oh, didn't know that! Thank you for the advice!
But I'll keep it like this because at max. like 3 people are going to use it.

~Hermen

Harry

2009-05-09 01:09:22

Make it .png. Seriously. People probably will not want to use it if it will take them like 5 minutes to upload the image because it is so big :/

ShowerThoughts

2009-05-09 01:12:13

Note: It is very fast with uploading and download!
It's just the conversion from a .bmp to a string which takes long.

NiCbaZ

2009-05-09 10:21:52

No it depends on your internet connection speed, a 15mb BMP could take 20 mins for some people.

ShowerThoughts

2009-05-09 21:15:52

Look a 20mb string is SUPER LONG But that takes max 1 min(at max) for me it's like 1 sec.
The converting takes very long! Like 20 minutes.
If you have a really big image, like a full screenshot of your screen. It takes like 20 minutes.
But normal pictures like 500 * 500 can take few mins for me like 3 I thought.
and yes the uploading is once.
The downloading goes VERY VERY fast.

IMO, you don't have to use, I would like it though.
It's specially for people with forms. that want a picture.
It takes some time but you get something back for it.
- No long ugly bmp in your script(you can put a image in a rar but than you need a rar, most people prefer just 1 .scar.
- They cannot easily steal the picture(it's not hard though).
- Fast enough.

Any questions ask me.

Ron

2009-05-09 22:21:32

Yeah man, when I start getting messages like this:

Error: Got a packet bigger than 'max_allowed_packet' bytes

You need to write an algorithm to make it PNG or JPEG so you can store about 10,000x more images, the images download faster for people with slower connections, and so its easier to show and put on forums.

By the way, change:

procedure PreviewPicture;

to

procedure PreviewPicture(Name : String);

~Ron

ShowerThoughts

2009-05-09 22:25:16

Thanks, to use it on forums?
in the database it's always just a string.
SCAR does this.
BMP–>String–>SQL
SQL–>String–>BMP.

CBF to write a algorithm for jpeg.(No offence)
If I would do that I would make something in my current project in C#(something with uploading/downloading + images.)

Thanks for feedback.
I can't see the problem for uploading it once.
Since the downloading goes fast enough for a form.
Can you do threads in scar?

Harry

2009-05-09 22:33:58

There is code that has been written to allow screenshots in .png format, I think.

ShowerThoughts

2009-05-09 22:37:54

Our php script only checks the size of the string, so scar only has to do the stuff to the string.

Freddy1990

2009-05-11 08:04:51

From: Ron

You need to write an algorithm to make it PNG or JPEG so you can store about 10,000x more images, the images download faster for people with slower connections, and so its easier to show and put on forums.


JPEG will reduce the image quality, it's lossless, even at maximum quality, the bitmap will get distorted which might make it fail with FindBitmap and such

Harry

2009-05-11 08:12:12

From: Freddy1990
JPEG will reduce the image quality, it's lossless, even at maximum quality, the bitmap will get distorted which might make it fail with FindBitmap and such

lossy*. <3

Freddy1990

2009-05-12 13:49:39

From: Harry
lossy*. <3


Woops, my bad :P Typo <3

Ron

2009-05-13 06:58:25

Oh is this script solely for scar bitmaps? because the first post doesn't say it. I'm just saying it would be nice if you could upload other image file types.

Da 0wner

2009-05-13 07:14:30

Tootoot222 and me created a PictureDatabase script.


Grammar pl0x.
me := I;

ShowerThoughts

2009-05-19 00:26:57

From: Da 0wner
Grammar pl0x.
me := I;


Orlly?
Never have known that!