How to convert png file to higher resolution file

Discussion in 'iOS Programming' started by theprizerevealed, Jul 31, 2019.

  1. theprizerevealed macrumors regular

    Joined:
    Feb 26, 2016
    #1
    I wish to know if there is a native tool on macOS mojave to convert png files to a higher resolution suitable for ipad pro third generation. There are many files and so I'm searching for a program that can process numerous files automatically.

    If not, is there something available on the Apple app store that might do the trick? I don't wish to use relatively unknown third party tools because of privacy reasons. thanks
     
  2. chown33 Moderator

    Staff Member

    Joined:
    Aug 9, 2009
    Location:
    bedlam
    #2
    The 'sips' command is usable in Terminal, a shell script, or in a Run Shell Script step of an Automator workflow.

    Here's the man page:
    https://ss64.com/osx/sips.html

    You'll want the --resampleHeightWidthMax option if you want to preserve aspect ratio.

    You can also read the man page in Terminal with:
    Code:
    man sips

    If you use Automator, it has some image resizing actions (Scale Images) that don't need a shell script. As it turns out, they run 'sips' to perform their task.
     
  3. theprizerevealed thread starter macrumors regular

    Joined:
    Feb 26, 2016
    #3
    well, unfortunately this does not appear to do what I wish it to do. Using this command:

    Code:
     
    for i in *.png; do sips -s format jpeg -s formatOptions 100 "${i}" --out "${i%png}jpg"; done   
    It converts all of the png files in the folder to jpeg just fine. However when I check the dots per inch when I open an image file in Preview and use the Inspector to check the number - the dpi remains the same for the corresponding jpeg file as it was for the png file!

    I need some program that can increase the resolution (isn't that the dot per inch?).
     
  4. chown33 Moderator

    Staff Member

    Joined:
    Aug 9, 2009
    Location:
    bedlam
    #4
    As I understand DPI for JPEG files, it's a suggestion intended for printing, roughly speaking. There are articles explaining more that show up by googling: jpeg file dpi


    To change the number of pixels, which is what I think you're asking for, use one of the:
    --resampleXXX
    operations. If you're increasing the dimensions, then you'll get pixelation if the increase is significant.

    If the images have different sizes, then you can use 'sips' to read pixelHeight or pixelWidth first, put that number into a shell var, then calculate a new value by multiplying it in a $(( arithmetic expression )) in bash, then use that new value in a --resampleXXX operation.
     
  5. theprizerevealed thread starter macrumors regular

    Joined:
    Feb 26, 2016
    #5
    Thanks, however many of these files have widely varying aspect ratios (lengths of heights and widths). I don't wish to set a standard height and width - simply to increase the number of pixels for greater definition, clarity and resolution.
     
  6. theprizerevealed thread starter macrumors regular

    Joined:
    Feb 26, 2016
    #6
    well, this is the only other way I could find to solve this problem but it still doesn't do what I need: https://www.wikihow.tech/Change-Picture-Resolution-on-PC-or-Mac

    Maybe I'm attempting this wrongly? There are 3 different versions of the image files in the Assets in Xcode - 1X , 2X and 3x. Is there some way to force Xcode to use one of the higher resolution image files?
     
  7. PhoneyDeveloper macrumors 68040

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #7
    You can't really make the resolution of an image greater than it is. You can make the image bigger but the information in the image will be the same. iOS doesn't care about dpi. That's only a suggestion anyway. iOS will pick the best match from among the three images provided with a particular name. So on a 3x screen it will prefer the @3x image. If there is none it will use the @2x image. And if that's not available it will pick the 1x image.

    So you can choose to ignore the @3x images if you don't have them and iOS will display the 2x image and scale it for you. Or you can convert the 1x or 2x images to the 3x size. It's just a matter of the image dimensions. So a 100x100 1x image would have a 200x200 @2x image and 300x300 @3x image to match it.

    In general png is preferred over jpg because png is lossless while jpg loses pixels when compressed.

    The apps most used for image manipulation for iOS are Photoshop and Sketch, AFAIK.
     

Share This Page

6 July 31, 2019