B4J Question [Server][No-UI application] image manipulation library ?

mindful

Active Member
Licensed User
Hi I have a project in B4J with jServer and ABMaterial and I am in the need of a b4j or java library which I can use to crop and/or resize images. I want to allow users to upload profile photos and other photos that need to be of a fixed size let's say 100x100 but the user uploads some different size or a high definition image so I need to reduce the size of the image also the quality (in some cases) ...

Can anyone point me in the right direction ?
 

Roycefer

Well-Known Member
Licensed User
Longtime User
I haven't looked at it too closely but I think it might be possible to use Java's BufferedImage class to do some basic down-scaling or cropping.
 
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
you could try this:
http://www.irfanview.com/
Irfan view has a very simple and powerful command line interface. I use it a lot. It can process any kind of image formats with it's plugins.
see the command line functions here:
http://www.robvanderwoude.com/files/iviewcli.txt

You can call irfanview with jshell (this is an example code from one of my apps):
B4X:
Public Sub CreateHTMLThumbnail(ImagePath As String) As String
    Dim ThumbnailPath As String
  
    If ImagePath.StartsWith("file:/") Then
        ImagePath = ImagePath.Replace("file:/", "")
    End If
  
    If File.Exists(Main.IVIEW_PATH, "") Then
        ThumbnailPath = File.Combine(File.Dirapp, "resized.jpg")
  
        Dim Args(7) As String
        Args(0) = "" & ImagePath.Replace("file:/", "").Replace("/", "\") & ""
        Args(1) = "/resize=(0,64)"
        Args(2) = "/resample"
        Args(3) = "/aspectratio"
        Args(4) = "/jpgq=100"
        Args(5) = "/convert=" & ThumbnailPath.Replace("/", "\") & ""
        Args(6) = "/silent"
      
        Dim shl As Shell
        shl.Initialize("CreateHTMLThumbnail", Main.IVIEW_PATH, Args)
        shl.Run(5000)
    Else
        ThumbnailPath = ImagePath
    End If

    Return $"<a href='${iif(Not(ImagePath.Contains("http")), "file:/", "")}${iif(ImagePath.Replace("\", "/").StartsWith("//"), "//", "")}${ImagePath.Replace("\", "/")}' target='_blank'><img src='file://${ThumbnailPath.Replace("\", "/")}' width=auto height='64' align='top' Hspace='5' Vspace='5' alt='Image linked' /></a>"$
End Sub
 
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
Yes, this is the function:
B4X:
Sub iif(Condition As Boolean, RetTrue As object, RetFalse As Object) As Object
    If Condition Return RetTrue
    Return RetFalse
End Sub
edit: it stands of Inline IF
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…