Jump to content

Some kind of engine for...


12p

Recommended Posts

Creating images from simple strings or another arguments.

E.g: CAPTCHAS. Those uses texts on images, right? IDK how do those work, but someway it works with MANY random images. If this suggestion is accepted, it may help to reduce good download space.

Edited by Guest
Link to comment

  
function dxCreateCaptcha(length) 
   local c = createElement("dxCaptcha") 
   local alph = {"a","b", "c", "d", "e", "f", "g", "h", "i",  "insertmore"} 
   local captch = "" 
   for i=0, length do 
     if math.random(2)==2 then 
       captch = captch..alpha[math.random(#alph)] 
     else 
       captch = captch..math.random(0,9) 
     end 
   end 
   setElementData(c, "captcha", captch) 
   return c 
end 
function dxDrawCaptcha(captcha) 
     if not isElement(captcha) 
     -- bunch of dxDrawText calls 
end 
end 
  

sorry about the create element thing, i was just kinda bored

Link to comment

This is very easy to make, theres no need for a built-in solution. Simply have a library of small images of the numbers 0-9 and letters a-z client-side (client/images/captcha/a.png for example). Then, when a captcha code is needed, request a random string from the server. When the string is recieved, split it into a table, and then for each character in the string, draw the proper image. For example:

  
--The width of a captcha image will remain the same at all times 
local characterWidth, characterHeight = 48, 48 --These are static values, all captcha images should be the same size. 
local captchaCode = string.split(strCaptcha) --Where 'strCaptcha' is what is recieved from the server. 
  
local x = 0 --This should be whatever the actual gui element's x position is 
local y = 0 --Same for this 
--Draw the individual images 
for _, character in ipairs(captchaCode) do 
    dxDrawImage(x, y, characterWidth, characterHeight, "client/images/captcha/"..character..".png") 
    x = x + characterWidth 
end 
  

Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...