Read an .avif file and write it as .jpg or .png same folder using MBS

I want to Read an .avif file and write it as .jpg or .png same folder using MBS
this is as far as i got. any in-site will be help ful

Sub ConvertImage(imageFile As folderItem, newformat as string)

Dim OldImage As New ImageMagickQ32MBS
Dim NewImage As New ImageMagickQ32MBS
Dim i_Info As New IMImageInfoQ32MBS
Dim I As New IMImageQ32MBS

I = OldImage.ReadImageFromString(i_Info, imageFile.NativePath)

Which OS? macOS, Windows or Linux?

To use ImageMagick to read avif, you’d need an ImageMagick version with avif support built-in. Not all versions have that.

Mac OS 12.6 Monterey.
MBS end date: 202208
will MBS Image read .avif ?

// Came up with this after visiting MonkeyBread
// it compiles with no errors / i don't know if it will really work
Dim ImageFile as string = "image.avif"
Dim baseName As String = "image"
Dim targetFormat as String = ".jpg"
Dim Dir As FolderItem = Image-location
Dim Img As GMConvertMBS
Img.InputFile = Dir.Child(imageFile)
Img.OutputMagick = "jpg"
Img.OutputFile = Dir.Child(baseName + targetFormat)
Img.OutputPath = Dir.NativePath

You can use the macOS build-in tool “sips” to convert such images, e.g.

sips -s format jpeg original-file.avif --out converted.jpg

You can just use the shell to call it from Xojo. No Plugin needed.

yes i know that , i have a script i wrote using FFmpeg it does the conversion , also does it in batches .

however i wanted a drag and drop solution, drag 1 or more .avif files to a ListBox, and do the conversion auto

i might consider this method / xojo calling the shell

sh.error code 13 / a permssions error / using Xojo calling Shell class

Dim sh As New Shell
sh.Execute("chown www-data:www-data " + dir +"/*")
sh.Execute ("chmod 755 " + dir + "/*")
sh.Execute ("sips -s format jpeg " +  dir + "/" + imageFile + " --out " + dir + "/" + baseName + ".jpg")

While sh.IsRunning
  '' waiting for shell to finish running
wend

if sh.ErrorCode <> 0 Then
  WinImageConvert.ErrorLabel.Text =  "Error Converting File: Error: " + Str(sh.ErrorCode)
end if

what is the work around ? sudo?

Did you check paths?
dir may need escaping for special characters.

And your app names need to be full paths to make sure they work, e.g. “/usr/bin/sips”

Do you read error messages coming from the app?

yes paths are good. so if i download an image .avif from my vender
it saves with permissions i cannot read using Shell from Xojo,
if i do a screen capture of the image it will save as .png . the .png has permissions that will allow Xojo and Sh to read and process the file. If i create the image file i can process the image file.
I can drag and drop 1 or more files and it does work.

here is the code i worked out…

sub ConvertImage( ..., ...., ...)
Dim sh As New Shell

//sh.Execute("chown everyone:everyone " + dir +"/*")
sh.Execute ("chmod 755 " + dir + "/*")

sh.Execute ("sips -s format jpeg " +  dir + "/" + imageFile + " --out " + dir + "/" + baseName + ".jpg")

While sh.IsRunning
  '' waiting for shell to finish running
wend

if sh.ErrorCode <> 0 Then
  WinImageConvert.ErrorLabel.Text =  "Error Converting File: Error: " + Str(sh.ErrorCode)
end if
end sub

DropObject()
// Check if the dropped item is a file
Dim baseName As String = InputBox.Text
If baseName = "" Then
  baseName = "converted_image"
End If

Dim i as Integer = 0

if obj <> Nil then
  
  Dim DropPath As FolderItem = obj.FolderItem
  
  FileN.Text = DropPath.Name
  FilePath.Text  = MainWin.CmpReplace(DropPath.NativePath, "\/[a-z0-9\.]+$", "")
  ConvertImageFormat(FilePath.Text, FileN.Text, "jpg", baseName + "-" + str(i))
  i = i + 1
else
  Return
End if

While obj.NextItem = True
  if obj <> Nil Then
    
    Dim DropPath As FolderItem = obj.FolderItem
    
    FileN.text = DropPath.Name
    FilePath.Text  = MainWin.CmpReplace(DropPath.NativePath, "\/[a-z0-9\.]+$", "")
    
    
    // Convert image to JPG
    ConvertImageFormat(FilePath.Text, FileN.Text, "jpg", baseName + "-" + str(i))
    
    // Add the converted and renamed file name to the ListBox
    // ImageList.AddRow(jpgFileName)
    i = i +1
  End If
  
Wend

A downloaded file may have a quarantine attribute assigned from the OS. This can lead to strange access issues.

Check for a quarantine attribute via xattr command:

xattr -l somefile
somefile: com.apple.quarantine: 0081;661538e2;Safari;

Try to remove the attribute via

xattr -d com.apple.quarantine somefile

PS: I wonder about the shell calls without a full path, e.g. “/usr/bin/sips” vs. “sips”