convert README

The project's README from github.com/p2r3/convert. As one markdown file: README.md.

Convert to it!

Truly universal online file converter.

Many online file conversion tools are boring and insecure. They only allow conversion between two formats in the same medium (images to images, videos to videos, etc.), and they require that you upload your files to some server.

This is not just terrible for privacy, it's also incredibly lame. What if you really need to convert an AVI video to a PDF document? Try to find an online tool for that, I dare you.

Convert.to.it aims to be a tool that "just works". You're almost guaranteed to get an output - perhaps not always the one you expected, but it'll try its best to not leave you hanging.

For a semi-technical overview of this tool, check out the video: https://youtu.be/btUbcsTbVA8

Usage

  1. Go to convert.to.it
  2. Click the big blue box to add your file (or just drag it on to the window).
  3. An input format should have been automatically selected. If it wasn't, yikes! Try searching for it, or if it's really not there, see the "Issues" section below.
  4. Select an output format from the second list. If you're on desktop, that's the one on the right side. If you're on mobile, it'll be somewhere lower down.
  5. Click Convert!
  6. Hopefully, after a bit (or a lot) of thinking, the program will spit out the file you wanted. If not, see the "Issues" section below.

Issues

Ever since the YouTube video released, we've been getting spammed with issues suggesting the addition of all kinds of niche file formats. To keep things organized, I've decided to specify what counts as a valid issue and what doesn't.

[!IMPORTANT] SIMPLY ASKING FOR A FILE FORMAT TO BE ADDED IS NOT A MEANINGFUL ISSUE!

There are thousands of file formats out there. It can take hours to add support for just one. The math is simple - we can't possibly support every single file. As such, simply listing your favorite file formats is not helpful. We already know that there are formats we don't support, we don't need tickets to tell us that.

When suggesting a file format, you must at minimum:

If this seems like a lot, please remember - a developer will have to do 100x more work to actually implement the format. Doing a bit of research not only saves them precious time, it also weeds out "unserious" proposals that would only bloat our to-do list.

If you're submitting a bug report, you only need to do step 1 - check if the problem isn't already reported by someone else. Bug reports are generally quite important otherwise.

Though please note, "converting X to Y doesn't work" is not a bug report. However, "converting X to Y works but not how I expected" likely is a bug report.

Deployment

Local development (Bun + Vite)

  1. Clone this repository WITH SUBMODULES. You can use git clone --recursive https://github.com/p2r3/convert for that. Omitting submodules will leave you missing a few dependencies.
  2. Install Bun.
  3. Run bun install to install dependencies.
  4. Run bunx vite to start the development server.

The following steps are optional, but recommended for performance:

When you first open the page, it'll take a while to generate the list of supported formats for each tool. If you open the console, you'll see it complaining a bunch about missing caches.

After this is done (indicated by a Built initial format list message in the console), use printSupportedFormatCache() to get a JSON string with the cache data. You can then save this string to cache.json to skip that loading screen on startup.

If you run into issues where your changes seem to not be applying, try disabling this cache.

Docker (prebuilt image)

Docker compose files live in the docker/ directory, so run compose with -f from the repository root:

docker compose -f docker/docker-compose.yml up -d

Alternatively download the docker-compose.yml separately and start it by executing docker compose up -d in the same directory.

This runs the container on http://localhost:8080/convert/.

Docker (local build for development)

Use the override file to build the image locally:

docker compose -f docker/docker-compose.yml -f docker/docker-compose.override.yml up --build -d

The first Docker build is expected to be slow because Chromium and related system packages are installed in the build stage (needed for puppeteer in buildCache.js). Later builds are usually much faster due to Docker layer caching.

Contributing

The best way to contribute is by adding support for new file formats (duh). If you don't have a format to add but are eager to help, take a look at our issues. There are plenty of suggestions there.

Here's how adding a format works works:

Creating a handler

Each "tool" used for conversion has to be normalized to a standard form - effectively a "wrapper" that abstracts away the internal processes. These wrappers are available in src/handlers.

Below is a super barebones handler that does absolutely nothing. You can use this as a starting point for adding a new format:

// file: dummy.ts

import type { FileData, FileFormat, FormatHandler } from "../FormatHandler.ts";
import CommonFormats, { Category } from "src/CommonFormats.ts";

class dummyHandler implements FormatHandler {

  public name: string = "dummy";
  public supportedFormats: FileFormat[] = [
    // Example PNG format, with both input and output disabled
    CommonFormats.PNG.builder("png")
      .markLossless()
      .allowFrom(false)
      .allowTo(false),

    // Alternatively, if you need a custom format, define it like so:
    {
      name: "CompuServe Graphics Interchange Format (GIF)",
      format: "gif",
      extension: "gif",
      mime: "image/gif",
      from: false,
      to: false,
      internal: "gif",
      category: [Category.IMAGE, CATEGORY.VIDEO], // See src/CommonFormats.ts for valid categories
      lossless: false
    },
  ];
  public ready: boolean = false;

  async init () {
    this.ready = true;
  }

  async doConvert (
    inputFiles: FileData[],
    inputFormat: FileFormat,
    outputFormat: FileFormat
  ): Promise<FileData[]> {
    const outputFiles: FileData[] = [];
    return outputFiles;
  }

}

export default dummyHandler;

For more details on how all of these components work, refer to the doc comments in src/FormatHandler.ts. You can also take a look at existing handlers to get a more practical example.

There are a few additional things that I want to point out in particular:

Testing

This project currently uses two levels of tests:

Not every handler needs a dedicated unit test, but handlers with non-trivial custom internal logic may benefit from having one.

Adding dependencies

If your tool requires an external dependency (which it likely does), there are currently two well-established ways of going about this:

Please try to avoid CDNs (Content Delivery Networks). They're really cool on paper, but they don't work well with TypeScript, and each one introduces a tiny bit of instability. For a project that leans heavily on external dependencies, those bits of instability can add up fast.

AI Usage Policy

If you intend to use an LLM, agent-enabled IDE, or other AI-driven tool for your contribution, please follow these guidelines:

Not adhering to these rules will likely get your pull request closed.

I figure that there are people who'd prefer if I merged zero AI-written code, but I believe that's simply not feasible. Just from a code integrity perspective, it's much safer to be transparent about AI usage and define clear guidelines than to make it a taboo and risk people "sneaking in" unvetted AI code. Making things illegal doesn't stop everyone from doing those things - some will still do them, just in secret and with less oversight.

convert (p2r3/convert)

Searching Database…

4.2K ·GitHub
这是干什么的?一个通用的在线文件转换工具,网址是 convert.to.it:你给它任意文件,选一个目标格式,它就能处理跨类型的转换,比如把 AVI 视频转成 PDF 文档——这类转换普通在线工具都不肯做。
它和别的在线转换工具有什么不同?大多数工具只能在同一类媒介内部转换(图片转图片、视频转视频),而且要求你把文件上传到它们的服务器。这个工具能跨媒介类型转换,而且完全在你的浏览器里运行。
我怎么转换一个文件?打开 convert.to.it,把文件拖到那个大蓝框里(输入格式会自动识别),再从第二个列表里选一个输出格式——电脑上在右侧,手机上在更靠下的位置——然后点 Convert。
它真的支持所有文件格式吗?不能——世面上有几千种格式,支持一种可能要花好几个小时,所以冷门的格式干脆就没有,你可能得到一个奇怪的结果,或者什么也转不出来。
我能自己搭一个实例吗?可以——有现成的 Docker 镜像:取 docker/ 目录里的 compose 文件,运行 docker compose up -d。如果要开发,先带子模块克隆仓库,安装 Bun,然后运行 bun install 和 bunx vite。
转换的时候我的文件会被上传到别的地方吗?不会——转换是在你自己的浏览器里本地完成的,而不是在远程服务器上,这正是这个项目对抗那些要求上传文件的转换工具的核心卖点。
背后真正干转换活的是什么?是打包进页面的知名工具的 WebAssembly 移植版:视频和音频用 FFmpeg,图片用 ImageMagick,压缩包用 7-zip 和 zstd,另外还有 Typst 渲染器和 PPTX 渲染器用于文档。新的转换工具会以 npm 包或 git 子模块的形式加到 src/handlers 下面。
作者为什么要做这个?用作者的话说,现有的在线转换工具又'无聊又不安全'——只能同类媒介互转,还得上传到服务器。目标是做一个'开箱即用'的转换工具,哪怕是奇怪的跨媒介需求,也很少会让你两手空空。
我怎么申请新增一种文件格式?只写一个格式名的工单会被拒掉。你必须先确认这个格式还没被支持也没人提过,描述清楚转换应该做什么,并附上一个实现参考或浏览器端的解决方案,而且许可证要兼容 GPL-2.0。在代码里,一种格式对应 src/handlers 下的一个包装类('handler'),命名方式类似 dummy.ts 里的 dummyHandler。
Creator
p2r3
Size
49.9 MB
Stars
4.2K
Age
10mo
Commits · 90 Days