Skip to content
This repository has been archived by the owner on Oct 19, 2020. It is now read-only.

An alternative way to this problem - glob traget png files #89

Open
MarcWeber opened this issue Dec 5, 2016 · 0 comments
Open

An alternative way to this problem - glob traget png files #89

MarcWeber opened this issue Dec 5, 2016 · 0 comments

Comments

@MarcWeber
Copy link

Problem 1: If you source image is not square you'll notice on "emulate" xcode failing.
Problem 2: Its not up to date

So why not go the different route, only "update" the images which are in the target directory?
I wrote a simple PHP script instead.

The strategy is: resize always from origin to dest.
Use the png files in destination directories - thereby its always up to date.

So I was able to also create launchimages easily by adding a second directory.

Maybe it would even be best if the image files could be configured in the project directory so that you can avoid some which are important to you.

Maybe this code helps somebody as well.

    ## generate icons
    <?php

    $app_name = "";

    $source = "icon.png";
      $target_dirs = ["platforms/ios/$app_name/Images.xcassets/LaunchImage.launchimage/" , "platforms/ios/$app_name/Images.xcassets/AppIcon.appiconset/"];

    foreach ($target_dirs as $td) {
      foreach(glob($td."/*.png") as $file){
        echo $file."\n";
        $img_source = imagecreatefromstring(file_get_contents($source));
        $size_source = getimagesize($source);
        $size_target = getimagesize($file);
        $img_target = imagecreatefromstring(file_get_contents($file));

        imagecolortransparent($img_target, imagecolorallocatealpha($img_target, 0, 0, 0, 127));
        imagealphablending($img_target, false);
        imagesavealpha($img_target, true);

        imagecopyresampled($img_target, $img_source, 0, 0, 0, 0, $size_target[0], $size_target[1], $size_source[0], $size_source[1]);
        imagepng($img_target, $file);
      }

    }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant