Giter Club home page Giter Club logo

stopka's Introduction

imgit logo


npm codefactor codecov codeql


Convert media links to optimized HTML

Images, video and YouTube: fetch, encode, scale, lazyload – for best UX and Web Vitals — imgit is a JavaScript package and set of plugins for popular web frameworks to enhance user experience when interacting with media-heavy websites, such as blogs, landings, portfolios and documentation sites.

Features

✨ Builds optimized HTML for media URLs, markdown or JSX tags

⚡ Encodes to AV1/AVIF utilizing GPU acceleration

♻️ Supports JPG, A/PNG, GIF, WEBM/P, AVI, MKV, TIFF, PSD and more

🌊 Generates tiny blurred covers cross-faded into HD source on lazy-load

📐 Scales the content while preserving HD original for high-DPI displays

🌐 Fetches sources from remote URLs, uploads optimized versions to CDN

🗺️ Plugs into Astro, Svelte, VitePress and more; runs on Node, Deno and Bun

🎬 Get Started

http://imgit.dev/guide

stopka's People

Contributors

elringus avatar

Stargazers

Luke Davis avatar Josh avatar Omak Oorzhak avatar Josef Ježek avatar Marco Dizo avatar Tristan F. avatar Ben Herbst avatar Beto Garcia avatar Jordi avatar Maxym avatar Amine avatar Kainoa Kanter avatar Nazar Kornienko avatar PlatformKit avatar Not Existing avatar Nicolas Marshall avatar Scott Willsey avatar Dane Miller avatar Steven Evans avatar Sirvent avatar

Watchers

 avatar

Forkers

fryuni

stopka's Issues

Markdow Output

I added the following to my Markdown file

![](/images/learn-javascript/spa/what/google.mp4)

Here's the output I got from this Markdown file:

<p><img src="/images/learn-javascript/spa/what/google.mp4" alt=""></p>

No transformation was done on it.

Sniff MIME

Instead of resolving content MIME type via file extension, consider using file --mime-type utility available by default on Linux and Mac. On Windows similar is available via file utility available on choco.

Image Paths

Imgit with Astro fetches the file from the public directory. But there are many instances where I want to fetch images from the /src/assets directory instead (since I use Astro's image optimization tool as well). Is it possible to remove the /public?

Example 
// Passed in value 
const test = await import('imgit:/asset/image.png') 

// Path used now
// /absolute-path-to-project/public/src/asset/image.png

// Preferred path 
// /absolute-path-to-project/src/asset/image.png

Invalid type declarations for covariant field in AstroIntegration

The type declared for the Astro plugin specifies unknown[] for Vite's plugin config. This is incompatible with the real AstroIntegration type from astro.

astro.config.mts:110:5 - error TS2322: Type 'AstroIntegration' is not assignable to type 'false | AstroIntegration | (false | AstroIntegration | null | undefined)[] | null | undefined'.
  Type 'AstroIntegration' is not assignable to type 'import("/home/lotus/Workspace/blog/node_modules/.pnpm/[email protected][email protected]/node_modules/astro/dist/@types/astro").AstroIntegration'.
    The types of 'hooks['astro:config:setup']' are incompatible between these types.
      Type '((options: { injectScript: AstroInjector; updateConfig: (config: { vite: { plugins: unknown[]; }; }) => void; }) => void | Promise<void>) | undefined' is not assignable to type '((options: { config: AstroConfig; command: "build" | "dev" | "preview"; isRestart: boolean; updateConfig: (newConfig: DeepPartial<AstroConfig>) => AstroConfig; ... 8 more ...; logger: AstroIntegrationLogger; }) => void | Promise<...>) | undefined'.
        Type '(options: { injectScript: AstroInjector; updateConfig: (config: { vite: { plugins: unknown[]; }; }) => void; }) => void | Promise<void>' is not assignable to type '(options: { config: AstroConfig; command: "build" | "dev" | "preview"; isRestart: boolean; updateConfig: (newConfig: DeepPartial<AstroConfig>) => AstroConfig; ... 8 more ...; logger: AstroIntegrationLogger; }) => void | Promise<...>'.
          Types of parameters 'options' and 'options' are incompatible.
            Type '{ config: AstroConfig; command: "build" | "dev" | "preview"; isRestart: boolean; updateConfig: (newConfig: DeepPartial<AstroConfig>) => AstroConfig; ... 8 more ...; logger: AstroIntegrationLogger; }' is not assignable to type '{ injectScript: AstroInjector; updateConfig: (config: { vite: { plugins: unknown[]; }; }) => void; }'.
              Types of property 'updateConfig' are incompatible.
                Type '(newConfig: DeepPartial<AstroConfig>) => AstroConfig' is not assignable to type '(config: { vite: { plugins: unknown[]; }; }) => void'.
                  Types of parameters 'newConfig' and 'config' are incompatible.
                    Type '{ vite: { plugins: unknown[]; }; }' is not assignable to type 'DeepPartial<AstroConfig>'.
                      The types of 'vite.plugins' are incompatible between these types.
                        Type 'unknown[]' is not assignable to type 'DeepPartial<PluginOption[] | undefined>'.
                          Type 'unknown' is not assignable to type 'PluginOption'.

110     imgit({}),
Print of the error formatted

image

updateConfig: (config: { vite: { plugins: unknown[] } }) => void;

That plugins: unknown[] is inside a function parameter, making the type of updateConfig contravariant over it. But the updateConfig field is itself part of a function parameter, meaning that astro:config:setup and by extension AstroIntegration contravariant over updateConfig. Transitively, AstroIntegration is covariant over the plugins field.

This means that assigning this AstroIntegration type over Astro's actual type would require unknown to be assignable to Vite's PluginOption, but of course unknown is not assignable to anything except itself by definition (since it is a top type).

The field should either:

  • Be properly typed using Vite's PluginOption
  • Be typed as a subtype of Vite's PluginOptions, possibly with only the used properties
  • Be typed with any, which is both a top and bottom type and accepts any assignment in both directions

Remote image being processed as a video

I got this on my markdown:

![xkcd about workflow](https://imgs.xkcd.com/comics/workflow.png)

Imgit tries to invoke ffmpeg and convert it to av1, which throws this error:

21:00:09 [ERROR] [vite] [imgit] Command failed: ffmpeg -y -loglevel error -i "/home/lotus/Workspace/blog/public/imgit/fetched/imgs.xkcd.com-comics-workflow.png" -c:v libaom-av1 -still-picture 1 -crf 23 -cpu-used 5 -an -filter_complex "[0:v]scale=iw*1:-1" "/home/lotus/Workspace/blog/public/imgit/encoded/[email protected]"
Unrecognized option 'still-picture'.
Error splitting the argument list: Option not found

ffmpeg info:

ffmpeg version 6.0 Copyright (c) 2000-2023 the FFmpeg developers
  built with gcc 12.3.0 (GCC)
  configuration: --disable-static --prefix=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-ffmpeg-6.0 --target_os=linux --arch=x86_64 --pkg-config=pkg-config --enable-gpl --enable-version3 --disable-nonfree --enable-shared --enable-pic --disable-small --enable-runtime-cpudetect --disable-gray --enable-swscale-alpha --enable-hardcoded-tables --enable-safe-bitstream-reader --enable-pthreads --disable-w32threads --disable-os2threads --enable-network --enable-pixelutils --datadir=/nix/store/5zl2754g2r43yp553634fzbligcvj172-ffmpeg-6.0-data/share/ffmpeg --enable-ffmpeg --disable-ffplay --enable-ffprobe --bindir=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-ffmpeg-6.0-bin/bin --enable-avcodec --enable-avdevice --enable-avfilter --enable-avformat --enable-avutil --enable-postproc --enable-swresample --enable-swscale --libdir=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-ffmpeg-6.0-lib/lib --incdir=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-ffmpeg-6.0-dev/include --enable-doc --enable-htmlpages --enable-manpages --mandir=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-ffmpeg-6.0-man/share/man --enable-podpages --enable-txtpages --docdir=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-ffmpeg-6.0-doc/share/doc/ffmpeg --enable-alsa --enable-bzlib --disable-libcelt --disable-cuda --disable-cuda-llvm --enable-libdav1d --disable-libfdk-aac --disable-libflite --enable-fontconfig --enable-libfreetype --disable-frei0r --disable-libfribidi --disable-libgme --enable-gnutls --disable-libgsm --disable-ladspa --enable-libmp3lame --disable-libaom --enable-libass --disable-libbluray --disable-libbs2b --disable-libdc1394 --enable-libdrm --enable-iconv --disable-libjack --disable-libmfx --disable-libmodplug --disable-libmysofa --enable-libopus --disable-librsvg --enable-libsrt --enable-libssh --disable-libtensorflow --enable-libtheora --enable-libv4l2 --enable-v4l2-m2m --enable-vaapi --enable-vdpau --enable-libvorbis --disable-libvmaf --enable-libvpx --disable-libwebp --disable-xlib --disable-libxcb --disable-libxcb-shm --disable-libxcb-xfixes --disable-libxcb-shape --disable-libxml2 --enable-lzma --enable-cuvid --enable-nvdec --enable-nvenc --disable-openal --disable-opencl --disable-libopencore-amrnb --disable-opengl --disable-libopenh264 --disable-libopenjpeg --disable-libopenmpt --enable-libpulse --disable-librav1e --enable-libsvtav1 --disable-librtmp --enable-sdl2 --enable-libsoxr --enable-libspeex --disable-libvidstab --disable-libvo-amrwbenc --enable-libx264 --enable-libx265 --disable-libxavs --enable-libxvid --disable-libzmq --enable-libzimg --enable-zlib --disable-vulkan --disable-libglslang --disable-libsmbclient --disable-debug --enable-optimizations --disable-extra-warnings --disable-stripping
  libavutil      58.  2.100 / 58.  2.100
  libavcodec     60.  3.100 / 60.  3.100
  libavformat    60.  3.100 / 60.  3.100
  libavdevice    60.  1.100 / 60.  1.100
  libavfilter     9.  3.100 /  9.  3.100
  libswscale      7.  1.100 /  7.  1.100
  libswresample   4. 10.100 /  4. 10.100
  libpostproc    57.  1.100 / 57.  1.100
Hyper fast Audio and Video encoder

Dynamic imports?

Possible to use dynamic imports with this with Astro? I tried and it got an error. Here's a quick screenshot.

CleanShot 2024-04-05 at 01 10 08

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.