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)
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
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
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