{"id":17101257,"url":"https://github.com/hackerb9/mktrans","last_synced_at":"2025-04-16T18:52:04.323Z","repository":{"id":47281867,"uuid":"94316094","full_name":"hackerb9/mktrans","owner":"hackerb9","description":"Make background transparent using antialiased alpha channel","archived":false,"fork":false,"pushed_at":"2024-08-09T04:20:33.000Z","size":1837,"stargazers_count":65,"open_issues_count":2,"forks_count":12,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-29T05:34:19.291Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hackerb9.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-14T09:53:14.000Z","updated_at":"2024-11-29T20:49:51.000Z","dependencies_parsed_at":"2024-11-07T17:00:54.794Z","dependency_job_id":"71f003ca-62c5-460e-9a5c-7b219ef4aa11","html_url":"https://github.com/hackerb9/mktrans","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackerb9%2Fmktrans","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackerb9%2Fmktrans/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackerb9%2Fmktrans/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackerb9%2Fmktrans/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hackerb9","download_url":"https://codeload.github.com/hackerb9/mktrans/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249266646,"owners_count":21240792,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T15:24:31.163Z","updated_at":"2025-04-16T18:52:04.305Z","avatar_url":"https://github.com/hackerb9.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"README.md.d/a-transparent-transparent (with -S).png\" alt=\"Astrolabe\" width=\"25%\" align=\"right\"\u003e\n\n# mktrans\n\nConvert images into shaped transparent pngs by floodfilling the\nbackground with transparency (antialiased alpha channel).\n\nTop left pixel is assumed to be the background color and floodfill\nis from image edges, unless a different starting pixel is specified.\n\n## Example\n\nThis program is meant to be quick and simple to use, so most of the\ntime simply specifying a filename, such as foo.jpg, is all you need.\n\n    mktrans foo.jpg\n\n(Result will be in foo*-transparent.png*.)\n\nIf too much or too little of the image is turning transparent, you can\nspecify a different \"fuzz\" factor.\n\n    mktrans -f 10 foo.jpg\n\n## Sample results\n\nFor a quick sample using the ImageMagick logo, run these commands:\n\n    convert logo: logo.png\n    mktrans logo.png\n    display logo-transparent.png\n\n[![After flattening on a saddle brown background](https://i.imgur.com/Exrm0tD.png)](https://i.imgur.com/PReCAca.png)\n\n## Installation\n\nIt's just a shell script, so just download the mktrans file, mark it executable, and put it in your bin directory.\n\n    wget https://github.com/hackerb9/mktrans/raw/master/mktrans\n    chmod +x mktrans\n    mv mktrans /usr/local/bin/\n\nNote: You will need to have [**imagemagick**](https://imagemagick.org/index.php) for it to work. You can find instructions on how to download it [here](https://imagemagick.org/script/download.php).\n\n## All flags and complete usage\n\n    Usage: mktrans [-f \u003cfuzz\u003e] [-s|-S] [-v] \u003cfiles ... \u003e\n\n        -f \u003cfuzz\u003e: How loosely to match the background color (default 20%)\n               -s: Use speedy antialiasing (much faster, slightly less acurate) \n               -S: Do not antialias transparency (useful for repeated runs)\n       -p \u003cx\u003e,\u003cy\u003e: Floodfills from pixel at x,y instead of 0,0\n               -v: Verbose\n\nOutput filenames will be the same as input, except suffixed with\n`-transparent.png`. E.g., `mktrans foo.gif bar.jpg` creates\n`foo-transparent.png` and `bar-transparent.png`.\n\n### About -f *fuzz*\n\n*Fuzz* is how far off the background color can be (in percent). You\nusually won't have to change this. If fuzz is too high, parts of the\nforeground image will be missing. If fuzz is too low, parts of the\nbackground will not be removed. On certain images it may help to tweak\nthe fuzz level to get good antialiasing. (Not losing too much of the\nedge, nor leaving any halos).\n\n### About -s (speedily skip subpixels)\n\nBy default this script creates an antialiased (blurred) alpha channel\nthat is also eroded by half a pixel to avoid halos. Of course,\nImageMagick's morphological operations don't (yet?) work at the\nsubpixel level, so I'm blowing up the alpha channel to 200% before\neroding. Since this can be slow on large images, consider using the\n'-s' option which tries to antialias without the subpixel eroding.\n\n### About -S (Supress antialiasing completely)\n\nSimilar to -s, but does not antialias at all. Useful with with -p, below.\nSee an example of why you'd use -S in [astrolabe.md](astrolabe.md).\n\n### About -p *x*,*y*\n\n*X*,*y* specifies which pixel to start floodfilling from, instead of 0,0.\nYou probably should just _ignore_ this option and use The GIMP for\nmore fiddly, complex images.\n\nTheoretically you can use -p to remove any lagoons that got missed by\na first floodfill. Note the letters 'a' and 'g' in the example below.\n\n    convert logo: foo.png\n    mktrans -p 160,100 foo.png\n    mv foo-transparent.png foo.png\n    mktrans -S -p 170,80 foo.png\n    mv foo-transparent.png foo.png\n    mktrans -S -p 195,65 foo.png\n    mv foo-transparent.png foo.png\n    mktrans -S -p 260,60 foo.png\n    mv foo-transparent.png foo.png\n    mktrans -S -p 285,55 foo.png\n    mv foo-transparent.png foo.png\n    mktrans foo.png\n    mv foo-transparent.png logo-transparent.png\n    \n[![Using -p to fill lagoons](https://i.imgur.com/Hxl1a1A.png)](https://i.imgur.com/CmbUnHk.png)\n\nYou can find the correct coordinates for a pixel by using\nImageMagick's `display` command and then middle-clicking on the image.\nUnfortunately, ImageMagick has no way to use that feature from a shell\nscript. If it did, this script could simply ask you to click on all\nthe start points of the image.\n\n## Bugs\n\n* The -p option is ugly and probably nobody wants to use it. Maybe I\n  should remove it just to make the documentation shorter and clearer.\n  Also, nearly every single bug listed here is due to -p existing.\n\n* Running this script on an image that already has transparency will\n  erode the image due to the antialiasing. Using -S is a workaround,\n  but is not very satisfactory. Perhaps this script should remove any\n  existing transparency before manipulating the image and then add it\n  back in at the end. But then again, how often are people going to\n  want to do that? The only use I can think of is when using -p.\n\n* Because of the previous bug, if you do use -p to fill lots of\n  lagoons, you'll probably want to use -S at the same time.\n  (Should this be done automatically if the image already has\n  transparency? Yuck, more complexity.)\n\n  See the [astrolabe](astrolabe.md) example where running mktrans a\n  second time on a specific pixel requires the use of -S so as to\n  not cause the image to be eroded.\n    \n            mktrans a.png\n            mktrans -p 258,54 a-transparent.png\n            mv a-transparent-transparent.png a-transparent-transparent' without -S).png\n            mktrans -S -p 258,54 a-transparent.png\n            mv a-transparent-transparent.png a-transparent-transparent' with -S).png\n\n* Finding the coordinates for -p is a pain. (Tip: middle click on\n  image when viewing with `display`). It'd be nice if there was a -P\n  option which let the user click on a point (or multiple points) in\n  the image to start the floodfill.\n\n* Instead of choosing coordinates, we could use ImageMagick's\n  connected components labeling (blob extraction) to give people a\n  choice of which lagoons to fill. \n\n\n## See Also\n\nThis is similar to ImageMagick's\n[\"bg_removal\"](https://www.imagemagick.org/Usage/scripts/bg_removal)\nscript, but much higher quality. (It's also faster and simpler to use.) \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhackerb9%2Fmktrans","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhackerb9%2Fmktrans","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhackerb9%2Fmktrans/lists"}