Execute a shell command?

This was a sub-question in a different thread, so I will ask it here (with a title which is more appropriate to the question).

Does anyone know why this line of code works:

newpic.save(f, picture.SaveAsJPEG, 100)

But this does not work:

Dim s As New Shell s.mode = 0 s.Execute ("sips -s format png -Z 256 picture --out ~/Desktop/256x256.png")

The second code segments compiles fine, but when run - no png is created on the desktop?

You need to:

s.Execute("sips", "-s format png -Z ...")

The first parameter is the executable. You may need the full path if it is not in the system path. The second parameter are parameters to send to the first.

what does s.result say?
is sips installed? and if so, is it on the “path”?
assuming this is OSX, since sips is an OSX utility

here is code I use to locate SIPS

  // Look for SIPS ... required for GIF and TIFF output
  For x=0 To 1
    If f=Nil Then Exit For 
    If x=1 Then f=f.child("developer")
    If f=Nil Then Continue
    If f=Nil Then Continue
    If Not f.exists Then Continue
    If f=Nil Then Continue
    If Not f.exists Then Continue
    If f=Nil Then Continue
    If flag Then Exit For
  Next x

and some code to call it

    s="sips -s format "+sips_format+" "+temp_file.shellpath+" --out "+xfile.shellPath
    sh.Mode = 0
    sh.Execute s
    If InStr(sh.Result,"command not found")>0 Then 
      myMsgBox "SIPS Not Found^The Image Conversion utility 'SIPS'^was not located on this computer.^^This is required for GIF and TIFF file^formats.",16
    End If

I have never installed sips onto Mavericks, and had no idea it needed to be installed (I presumed it was part of the OS).
I am simply trying to save an image (preferably as a png), but keep the quality at the absolute maximum.

I was informed that saving as a jpg with 100 quality still produced a lower quality image than a png using sips?

If sips has to be installed on the user’s machine just to save as a high quality png, then I will have to settle for a lower quality jpg :frowning:

Thanks guys.

SIPS IS installed by default on OSX…

and I seriously doubt that SIP will save a higher quality version of a PNG, the the normal Xojo SavePicture as PNG does.

Yes, a PNG is better quality than a JPG… but if you start with a JPG and save as a PNG, you do not IMPROVE the quality, while starting with a PNG and saving as a JPG will usually lower the quality (usually,not always)

The only reason by app uses SIPS at all is to save pics as GIF or TIF, all JPG and PNG processing is done with built in XOJO features

so my opinon… save your PNG as

newpic.save(f, picture.SaveAsPNG)

How do I link to a specific post in another thread?
Then I can show you what I was advised.

just go to that post… copy the link… paste it here…

And regardless of what you were advised… the end result cannot be “better” than what you started with.

I can only post a link to the thread itself - not the specific post :frowning:
Scroll up from the bottom until you see the 2 circular images.



That is talking about RESIZING an image… and yeah. SIPS probably does a better job…
You were talking about just SAVING it… there SIPS will offer nothing extra.

After adding the necessary dim statements etc. I ran your code Dave, and nothing at all happened - just an empty window :frowning:
I can’t seem to find the full path?

[quote=105071:@Jeremy Cowgar]You need to:

s.Execute("sips", "-s format png -Z ...")

The first parameter is the executable. You may need the full path if it is not in the system path. The second parameter are parameters to send to the first.[/quote]

After reading the docs here, I understand it can be done all on one line, but the above is preferred as if you have a space in the path to the executable, or the executable itself has a space, that will throw things off. For example:

s.Execute("/Users/Jeremy C/bin/sips", "-s format ...")

will work, but

s.Execute("/Users/Jeremy C/bin/sips -s format ...")

will not.

My code looks like this:

Dim s As New Shell s.mode = 0 s.Execute ("sips", " -s format png -Z 256 newpic --out ~/Desktop/256.png")

And I can’t enter the full path, as I cannot find the full path?

Look at my code… it tells you the path… that was the whole idea… find where SIPS is… and return a flag… you need to modify it to keep the path (F)

Of course running the code results in a empty window (if that is all you ran)… there is no visual component

to determine if in fact SIPS is installed (and to get the path)
and type “type sips” …without the quotes

Ok - I am going to have to give up on this.
I don’t understand this at all, and I even tried to include what I can gather should be the full path - but I still get NO png :frowning:

Dim s As New Shell s.mode = 0 s.Execute ("developer/usr/bin/sips", " -s format png -Z 256 newpic --out ~/Desktop/256.png")

Thanks for trying to help, but I will stick with crappy version of png.

Did you examine the SH.RESULT value? it will contain any error message…

plus… I believe your syntax is wrong

s.Execute (“sips”, " -s format png -Z 256 “+newpic+” --out ~/Desktop/256.png")
where newpic is a variable with the path of the picture to convert (newpic.nativepath perhaps)

This code works:

newpic = new picture(512,512,32)

newpic.graphics.drawpicture(pic, 0,0,512,512, 0,0,pic.width,pic.height)

f = SpecialFolder.Desktop.child("512.png")

//newpic.save(f, picture.SaveAsPNG)[/code]

This code doesn’t:

Dim s As New Shell s.mode = 0 s.Execute ("sips", " -s format png -Z 512 newpic --out ~/Desktop/512.png")

Ok… I’m done asking if you have checked SH.RESULTS… as that will most likely answer your question…

you (uncharacteristally) do not seem to be paying attention to what I’m saying.

A) your syntax is wrong… newpic needs to be the PATH
B) check RESULTS

Dave - I was paying attention, but I don’t understand what is being said :frowning:

In the terminal I was told that sips is in the following path:

I couldn’t do as you suggested because:

A) I have no idea how to even check sh.RESULTS

B) I do not know the path to the image because it is an image which gets dropped onto Canvas1 via the code below:

pic = picture.open(obj.FolderItem)

I am not ignoring your advice - I simply do not understand it, as I am still getting to grips with dropping images onto a canvas and storing them as picture objects. Then at the same time, I get problems with shell scripting which I no NOTHING about.


I will try and work out how to check sh.RESULTS now.

msgbox sh.result

and you do know the path … at least you 'working example" has a folderitem called newpic

note : SIPS only works with image FILES… so if you image does NOT exist on disk… it has to be saved BEFORE it can be transformed

Seriously Dave - please don’t be annoyed but I have to give up on this.
Your code produces numerous Does not Exist Errors (for me at least), so I can’t even check sh.Result, and I still cannot work out the path to newpic.

I am actually starting to get so angry over this ridiculous problem that I am starting to feel really ill.
I am way out of my depth here, and know when to quit.

I really appreciate your patience and attempts to help but this is just WAY beyond me at the moment.

Thanks anyway.