QBJS v0.7.0 - Release
#20
Another new feature introduced in 0.7.0 is the ability to trigger uploads and downloads to and from the browser from within your QBJS program.  The following example shows how to use this feature.  (As a bonus it also uses the new SaveImage method from the new 2D graphics library.)

Code: (Select All)
Import FS From "lib/io/fs.bas"
Import G2D From "lib/graphics/2d.bas"

Dim Shared img As Long

Screen _NewImage(600, 600, 32)

Print "Welcome to Image Decorator!"
Print "Press any key to upload an image file..."
Sleep

' Prompt the user to upload a PNG file
' and save it to the temp directory
' Call the OnUpload sub with complete
MkDir "temp"
FS.UploadFile "temp", ".png, .jpg", sub_OnUpload

' Wait for the image to be uploaded
Do
    _Limit 60
Loop Until img

' Decorate the image
DecorateImage

' Make a copy of the image
Dim imgCopy As Long
imgCopy = _CopyImage(_Dest)

' Save the image
Color 0
_PrintMode _KeepBackground
Print "Press any key to save the new image..."
Sleep

' Save the image to the virtual file system
G2D.SaveImage imgCopy, "temp/newimage.png"

' Prompt the user to download the image file
FS.DownloadFile "temp/newimage.png"


Sub OnUpload (filename As String)
    img = _LoadImage(filename)
End Sub

Sub DecorateImage
    ' Scale the image to fit the screen
    Dim As Double scale
    Dim As Integer w, h, x, y
    w = _Width(img)
    h = _Height(img)
    If w > h Then
        scale = h / w
        w = _Width
        h = w * scale
    Else
        scale = w / h
        h = _Height
        w = h * scale
    End If

    ' Center the image
    w = w - 50
    h = h - 50
    x = (_Width - w) / 2
    y = (_Height - h) / 2

    ' Draw a drop shadow
    Cls , 15
    G2D.Shadow _RGB(100, 100, 100), 8, 8, 15
    Line (x, y)-(x + w - 1, y + h - 1), 0, BF
    G2D.ShadowOff
   
    ' Draw the image
    _PutImage (x, y)-(x + w, y + h), img
End Sub

View in QBJS
Reply


Messages In This Thread
QBJS v0.7.0 - Release - by dbox - 05-26-2023, 06:23 PM
RE: QBJS v0.7.0 - Release - by dbox - 05-26-2023, 07:04 PM
RE: QBJS v0.7.0 - Release - by grymmjack - 06-03-2023, 10:05 PM
RE: QBJS v0.7.0 - Release - by dbox - 05-26-2023, 07:27 PM
RE: QBJS v0.7.0 - Release - by bplus - 05-26-2023, 10:16 PM
RE: QBJS v0.7.0 - Release - by dbox - 05-26-2023, 10:27 PM
RE: QBJS v0.7.0 - Release - by dbox - 05-26-2023, 10:48 PM
RE: QBJS v0.7.0 - Release - by bplus - 05-27-2023, 03:12 AM
RE: QBJS v0.7.0 - Release - by dbox - 05-27-2023, 02:39 PM
RE: QBJS v0.7.0 - Release - by Coolman - 05-29-2023, 11:20 AM
RE: QBJS v0.7.0 - Release - by dbox - 05-29-2023, 04:50 PM
RE: QBJS v0.7.0 - Release - by grymmjack - 05-29-2023, 11:55 PM
RE: QBJS v0.7.0 - Release - by grymmjack - 05-29-2023, 11:59 PM
RE: QBJS v0.7.0 - Release - by dbox - 05-30-2023, 01:19 AM
RE: QBJS v0.7.0 - Release - by dbox - 05-30-2023, 02:03 PM
RE: QBJS v0.7.0 - Release - by mnrvovrfc - 05-31-2023, 03:15 PM
RE: QBJS v0.7.0 - Release - by dbox - 06-01-2023, 01:22 PM
RE: QBJS v0.7.0 - Release - by dbox - 06-02-2023, 03:50 AM
RE: QBJS v0.7.0 - Release - by mnrvovrfc - 06-02-2023, 05:33 AM
RE: QBJS v0.7.0 - Release - by dbox - 06-12-2023, 07:48 PM



Users browsing this thread: 5 Guest(s)