```
--------------------------------
### Plaiceholder Implementation README License Acknowledgement
Source: https://github.com/joe-bell/plaiceholder/blob/main/CONTRIBUTING.md
This markdown snippet provides the required license and acknowledgement section for the README.md file of a Plaiceholder implementation. It specifies the Apache-2.0 license and credits the original author, Joe Bell.
```markdown
## License
Apache-2.0 License ©
### Acknowledgements
#### [Joe Bell](https://github.com/joe-bell) ([Plaiceholder](https://github.com/joe-bell/plaiceholder))
Copyright © 2020-2022, Joe Bell. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License").
```
--------------------------------
### Migrating Next.js Configuration
Source: https://github.com/joe-bell/plaiceholder/blob/main/docs/pages/docs/upgrading-to-3.mdx
Instructions for migrating a Next.js project's configuration file to support ESM, typically by renaming `next.config.js` to `next.config.mjs`.
```bash
Migrate your `next.config.js` to `next.config.mjs`
_(or `.ts` when supported)_
```
--------------------------------
### Astro Project Structure
Source: https://github.com/joe-bell/plaiceholder/blob/main/examples/astro/README.md
This snippet details the typical file and folder organization within an Astro project. It highlights the roles of `public/` for static assets, `src/components/`, `src/layouts/`, and `src/pages/` for Astro components and pages.
```bash
/
├── public/
│ └── favicon.svg
├── src/
│ ├── components/
│ │ └── Card.astro
│ ├── layouts/
│ │ └── Layout.astro
│ └── pages/
│ └── index.astro
└── package.json
```
--------------------------------
### Publish Packages
Source: https://github.com/joe-bell/plaiceholder/blob/main/CONTRIBUTING.md
Publishes all packages in the monorepo to npm. The -r flag indicates a recursive publish.
```sh
pnpm publish -r
```
--------------------------------
### Add Changesets
Source: https://github.com/joe-bell/plaiceholder/blob/main/CONTRIBUTING.md
Initiates the process of creating a changeset, which is used for managing releases and generating changelogs.
```sh
pnpm changeset
```
--------------------------------
### PHP Plaiceholder Implementation
Source: https://github.com/joe-bell/plaiceholder/blob/main/docs/pages/docs/community.mdx
An alternative implementation of Plaiceholder for PHP environments, allowing developers to generate blurred image placeholders using PHP.
```php
process('path/to/your/image.jpg');
// echo '
';
?>
```
--------------------------------
### Configure Next.js with Plaiceholder
Source: https://github.com/joe-bell/plaiceholder/blob/main/docs/pages/docs/plugins/next.mdx
Wraps your Next.js configuration object with the `withPlaiceholder` function. This ensures proper integration and that Plaiceholder functions run correctly within the Next.js environment. Your Next.js config file must use the `.mjs` extension.
```javascript
// @ts-check
import withPlaiceholder from "@plaiceholder/next";
/**
* @type {import('next').NextConfig}
*/
const config = {
// your Next.js config
};
export default withPlaiceholder(config);
```
--------------------------------
### Plaiceholder Implementation README Disclaimer
Source: https://github.com/joe-bell/plaiceholder/blob/main/CONTRIBUTING.md
This markdown snippet provides the required disclaimer to be placed at the top of a README.md file for any Plaiceholder implementation. It acknowledges the external maintenance and links to the original Plaiceholder project.
```markdown
An externally-maintained implementation of
Plaiceholder
---
```
--------------------------------
### Apply Styles to CSS LQIP
Source: https://github.com/joe-bell/plaiceholder/blob/main/docs/pages/docs/plugins/tailwind.mdx
Shows how to combine the `plaiceholder` class with other Tailwind CSS utility classes to style the generated LQIP, such as applying transformations and blur effects.
```html
```
--------------------------------
### Migrating Tailwind CSS Configuration
Source: https://github.com/joe-bell/plaiceholder/blob/main/docs/pages/docs/upgrading-to-3.mdx
Guidance on migrating a Tailwind CSS project's configuration file to ESM, usually by renaming `tailwind.config.js` to `tailwind.config.mjs` or `tailwind.config.ts`.
```bash
Migrate your `tailwind.config.js` to `tailwind.config.mjs` or `tailwind.config.ts`
```
--------------------------------
### Local Image Resolution in Node.js
Source: https://github.com/joe-bell/plaiceholder/blob/main/docs/pages/docs/upgrading-to-3.mdx
Demonstrates how to resolve local images using `getPlaiceholder` in a Node.js environment after upgrading to Plaiceholder 3.0. It reads a local file into a buffer and passes it to the function, extracting image metadata.
```javascript
import path from "node:path";
import fs from "node:fs/promises";
const getImage = async (src: string) => {
const buffer = await fs.readFile(path.join("./public", src));
const {
metadata: { height, width },
...plaiceholder
} = await getPlaiceholder(buffer, { size: 10 });
return {
...plaiceholder,
img: { src, height, width },
};
};
// Usage
const { base64, img } = await getImage("/assets/image/example.jpg");
```
--------------------------------
### Generate CSS LQIP with plaiceholder Class
Source: https://github.com/joe-bell/plaiceholder/blob/main/docs/pages/docs/plugins/tailwind.mdx
Demonstrates how to use the `plaiceholder-[image-slug]` class in HTML to generate a pure CSS LQIP for a specified image. The plugin resolves the image based on the configured resolver.
```html
```
--------------------------------
### Plaiceholder getPlaiceholder Function
Source: https://github.com/joe-bell/plaiceholder/blob/main/docs/pages/docs/usage.mdx
The core getPlaiceholder function takes an image input (Buffer) and optional configuration options to generate various placeholder formats. It leverages the Sharp library for image transformations.
```js
getPlaiceholder(input, options);
```
--------------------------------
### Generate CSS Placeholder (Local Image)
Source: https://github.com/joe-bell/plaiceholder/blob/main/docs/pages/docs/usage.mdx
Generates CSS styles for a low-res placeholder, outputting as a JavaScript style object with linear-gradients, from a local image. Requires reading the file into a Buffer.
```js
import fs from "node:fs/promises";
import { getPlaiceholder } from "plaiceholder";
try {
const file = await fs.readFile("/path-to-your-image.jpg");
const { css } = await getPlaiceholder(file);
console.log(css);
} catch (err) {
err;
}
// Logs
// {
// backgroundImage: "…"
// backgroundPosition: "…"
// backgroundSize: "…"
// backgroundRepeat: "…"
// }
```
--------------------------------
### Generate CSS Placeholder (Remote Image)
Source: https://github.com/joe-bell/plaiceholder/blob/main/docs/pages/docs/usage.mdx
Generates CSS styles for a low-res placeholder, outputting as a JavaScript style object with linear-gradients, from a remote image. Requires fetching the image and converting it to a Buffer.
```js
import { getPlaiceholder } from "plaiceholder";
try {
const src = "https://images.unsplash.com/photo-1621961458348-f013d219b50c";
const buffer = await fetch(src).then(async (res) =>
Buffer.from(await res.arrayBuffer())
);
const { css } = await getPlaiceholder(buffer);
console.log(css);
} catch (err) {
err;
}
// Logs
// {
// backgroundImage: "…"
// backgroundPosition: "…"
// backgroundSize: "…"
// backgroundRepeat: "…"
// }
```
--------------------------------
### Generate SVG Placeholder from Remote Image
Source: https://github.com/joe-bell/plaiceholder/blob/main/docs/pages/docs/usage.mdx
Fetches a remote image using its URL, converts it into an SVG placeholder using `getPlaiceholder`, and logs the SVG output. Requires `fetch` API.
```js
import { getPlaiceholder } from "plaiceholder";
try {
const src = "https://images.unsplash.com/photo-1621961458348-f013d219b50c";
const buffer = await fetch(src).then(async (res) =>
Buffer.from(await res.arrayBuffer())
);
const { svg } = await getPlaiceholder(buffer);
console.log(svg);
} catch (err) {
err;
}
// Logs
// [
// "svg",
// { ...svgProps }
// [
// [
// "rect",
// { ...rectProps }
// ],
// ...etc
// ]
// ]
```
--------------------------------
### Generate SVG Placeholder from Local Image
Source: https://github.com/joe-bell/plaiceholder/blob/main/docs/pages/docs/usage.mdx
Reads a local image file and converts it into an SVG placeholder using `getPlaiceholder`. The SVG output is logged to the console. Requires Node.js `fs` module.
```js
import fs from "node:fs/promises";
import { getPlaiceholder } from "plaiceholder";
try {
const file = await fs.readFile("/path-to-your-image.jpg");
const { svg } = await getPlaiceholder(file);
console.log(svg);
} catch (err) {
err;
}
// Logs
// [
// "svg",
// { ...svgProps }
// [
// [
// "rect",
// { ...rectProps }
// ],
// ...etc
// ]
// ]
```
--------------------------------
### Configure Tailwind CSS with plaiceholder Plugin
Source: https://github.com/joe-bell/plaiceholder/blob/main/docs/pages/docs/plugins/tailwind.mdx
Adds the plaiceholder plugin to your Tailwind CSS configuration file (`tailwind.config.mjs`). This enables the plugin's functionality for generating LQIPs.
```js
// @ts-check
import plaiceholder from "@plaiceholder/tailwindcss";
/** @type {import('tailwindcss').Config} */
export default {
content: [],
theme: {
extend: {},
},
variants: {},
plugins: [plaiceholder()],
};
```
--------------------------------
### Generate Base64 Placeholder (Local Image)
Source: https://github.com/joe-bell/plaiceholder/blob/main/docs/pages/docs/usage.mdx
Generates a Base64 encoded low-resolution image placeholder from a local file. Requires reading the file into a Buffer.
```js
import fs from "node:fs/promises";
import { getPlaiceholder } from "plaiceholder";
try {
const file = await fs.readFile("/path-to-your-image.jpg");
const { base64 } = await getPlaiceholder(file);
console.log(base64);
} catch (err) {
err;
}
// Logs
// data:image/jpeg;base64,/9j/2wBDAAYEBQY…
```
--------------------------------
### Generate img Attributes from Image Metadata
Source: https://github.com/joe-bell/plaiceholder/blob/main/docs/pages/docs/usage.mdx
Demonstrates how to use image metadata (specifically height and width) obtained via Plaiceholder to generate essential attributes for an `
` tag.
```javascript
import fs from "node:fs/promises";
import { getPlaiceholder } from "plaiceholder";
try {
const src = "/path-to-your-image.jpg";
const file = await fs.readFile(src);
const {
metadata: { height, width },
} = await getPlaiceholder(file);
const img = { src, height, width };
console.log(img);
} catch (err) {
err;
}
// Logs
// {
// src: '…',
// width: …,
// height: …,
// }
```
--------------------------------
### Generate Base64 Placeholder (Remote Image)
Source: https://github.com/joe-bell/plaiceholder/blob/main/docs/pages/docs/usage.mdx
Generates a Base64 encoded low-resolution image placeholder from a remote image URL. Requires fetching the image and converting it to a Buffer.
```js
import { getPlaiceholder } from "plaiceholder";
try {
const src = "https://images.unsplash.com/photo-1621961458348-f013d219b50c";
const buffer = await fetch(src).then(async (res) =>
Buffer.from(await res.arrayBuffer())
);
const { base64 } = await getPlaiceholder(buffer);
console.log(base64);
} catch (err) {
err;
}
// Logs
// data:image/jpeg;base64,/9j/2wBDAAYEBQY…
```
--------------------------------
### Configure Tailwind CSS with Custom Resolver
Source: https://github.com/joe-bell/plaiceholder/blob/main/docs/pages/docs/plugins/tailwind.mdx
Configures the plaiceholder Tailwind CSS plugin with a custom resolver function. This function dictates how image paths are read and converted into buffers, allowing for custom image loading logic.
```js
// @ts-check
import fs from "node:fs";
import path from "node:path";
import plaiceholder from "@plaiceholder/tailwindcss";
/** @type {import('tailwindcss').Config} */
export default {
content: [],
theme: {
extend: {},
},
variants: {},
plugins: [
plaiceholder({
resolver: (src) =>
fs.readFileSync(path.join("./public", `${src}.jpg`)),
}),
],
};
```
--------------------------------
### ESM Only Packages
Source: https://github.com/joe-bell/plaiceholder/blob/main/docs/pages/docs/faqs.mdx
This callout indicates that all plaiceholder packages are exclusively available in ECMAScript Module (ESM) format. This means they should be imported using `import` statements and are not compatible with CommonJS `require` syntax.
```typescript
import { Callout } from "nextra-theme-docs";
**`plaiceholder` packages are [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).**
```
--------------------------------
### ESM Only Packages Notification
Source: https://github.com/joe-bell/plaiceholder/blob/main/docs/pages/docs/upgrading-to-3.mdx
A notification indicating that Plaiceholder packages are now ESM only, requiring users to migrate their projects if they are currently using CommonJS.
```html
**`plaiceholder` packages are [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).**
```
--------------------------------
### Extract Image Source from plaiceholder Class
Source: https://github.com/joe-bell/plaiceholder/blob/main/docs/pages/docs/plugins/tailwind.mdx
Utilizes the `extractImgSrc` utility from `@plaiceholder/tailwindcss/utils` to parse a `plaiceholder` class string and extract the image source slug. This is useful for dynamic scenarios where the class name is generated.
```js
import { extractImgSrc } from "@plaiceholder/tailwindcss/utils";
const plaiceholder = "plaiceholder-[image-slug]";
const src = extractImgSrc(plaiceholder);
console.log(src);
// Logs
// "image-slug"
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.