Coder Social home page Coder Social logo

pepic's Introduction


PEPIC

Pepic is a small app that helps me to upload, store, convert and serve pictures or videos on your server.

I use it as media proxy for my pet-projects and on my blog. Pepic can convert, resize and optimize media files in-flight to save you monies and bandwidth. Internally it uses ffmpeg for videos and vips for images, which means it's quite fast and supports JPG, PNG, GIF, WEBP, SVG, HEIF, TIFF and wide range of video formats.

It's not meant to be used by anyone else except me. Use it only if you're brave. Scroll down this README for better alternatives.

๐Ÿค– How to run it locally

This command starts a local server on localhost:8118. Useful for development.

go run main.go serve --config ./etc/pepic/config.yml

โš ๏ธ If you're getting invalid flag in pkg-config error, run export CGO_CFLAGS_ALLOW="-Xpreprocessor" in advance

๐Ÿณ Running in Docker

  1. Get Docker

  2. Clone the repo

git clone [email protected]:vas3k/pepic.git
cd pepic
  1. Build and run the app
docker build .
docker run -p 8118:8118 -v ${PWD}/uploads:/app/uploads $(docker build -q .)
  1. Go to http://localhost:8118 and try uploading something. You should see uploaded images or videos in the data directory (./uploads) after that.

  2. Try to resize an image by adding a number of pixels to its URL. For example: https://localhost:8118/file.jpg -> https://localhost:8118/500/file.jpg

  3. Check out the etc/pepic/config.yml file. Some stuff is turned off by default. You can tweak them for yourself and rebuild the docker again (step 3) to apply them.

๐Ÿšข Production Usage

โš ๏ธ If you plan to host anything bigger than a blog, always put it behind CDN. CloudFlare offers a free one if you don't hate big corporations :D

Let's say, you want to host it on https://media.mydomain.org

1. Modify config/config.yml to your taste

global:
  host: 0.0.0.0 
  port: 8118  # internal host and port, leave it as it is
  base_url: "https://media.mydomain.org"
  secret_code: "secretpass"
  max_upload_size: "500M"

2. Build and run production docker

Don't forget to mount upload volume to store files on host (or you can lose those files when container will be killed).

docker run -p 8118:8118 -v /host/dir/uploads:/app/uploads $(docker build -q .)

If you prefer docker-compose, you can use it too. Check out the included docker-compose.example.yml. You can easily transform it into your favourite k8s config or whatever is fashionable this summer.

๐Ÿ‘ Don't forger to periodically backup the /host/dir/uploads directory just in case :)

3. Use nginx or your other favourite proxy

Just proxy all calls from the domain (media.mydomain.org) to pepic backend (0.0.0.0:8118). It can handle static files too.

server {
    listen 80;
    server_name media.mydomain.org;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_pass http://0.0.0.0:8118;
    }
}

๐Ÿ˜ Contributions

Contributions are welcome.

Open an Issue if you want to report a bug and propose an idea.

โœ… TODO

  • Tests :D
  • Upload by URL
  • Crop, rotate and other useful transformations (face blur? pre-loader generator?)
  • Live conversion by changing file's extension
  • Set format and quality during the upload (using GET/POST params?)

๐Ÿค” Alternatives

After reading all this, you probably realized how bad it is and looking for other alternatives. Here's my recommendations:

๐Ÿ‘ฉโ€๐Ÿ’ผ License

It's MIT.

Contact me if you have any questions โ€” [email protected].

โค๏ธ

pepic's People

Contributors

ndmitry avatar vas3k avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.