All Projects → marnusw → cloudinary-tiny-js

marnusw / cloudinary-tiny-js

Licence: MIT license
A much smaller alternative to cloudinary-core for client side image transformations

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to cloudinary-tiny-js

kap-cloudinary
Kap plugin - Share on Cloudinary
Stars: ✭ 14 (-51.72%)
Mutual labels:  cloudinary
Quora
Building An Exclusive Community of PEC Graduates and Students.The main features of the website are “PEC Quora” and “PEC Connect”
Stars: ✭ 26 (-10.34%)
Mutual labels:  cloudinary
cloudinary-module
Integration of Cloudinary to Nuxt.js
Stars: ✭ 129 (+344.83%)
Mutual labels:  cloudinary
nicolas-hoizey.com
The personal website/blog from Nicolas Hoizey, built with https://pack11ty.dev/
Stars: ✭ 77 (+165.52%)
Mutual labels:  cloudinary
ghost-on-heroku
One-button Heroku deploy for the Ghost 3.2.0 blogging platform.
Stars: ✭ 232 (+700%)
Mutual labels:  cloudinary
ghost-storage-cloudinary
🚀 A fully-featured and deeply tested Cloudinary Ghost storage adapter
Stars: ✭ 49 (+68.97%)
Mutual labels:  cloudinary
cloudinary-microurl
A tiny (346B), 0 dependency, fully-tested Cloudinary URL generator for JS
Stars: ✭ 14 (-51.72%)
Mutual labels:  cloudinary
video-to-markdown
How to embed a video in markdown? Here the answer. Add videos to your markdown files easier.
Stars: ✭ 159 (+448.28%)
Mutual labels:  cloudinary
uploading-files-react-node
Uploading files with React.js and Node.js
Stars: ✭ 33 (+13.79%)
Mutual labels:  cloudinary
mesan-nodejs-auth-crud-api
NodeJS Authentication and CRUD operations API -: Email Verification, Image Upload, Password Reset
Stars: ✭ 72 (+148.28%)
Mutual labels:  cloudinary
shodipoayomide.com
🔥 🚀 Personal Blog by Shodipo Ayomide. Currently writing on things around Developer Advocacy, Software Engineering, and IOT
Stars: ✭ 89 (+206.9%)
Mutual labels:  cloudinary
hrms-backend
⚙ Multi-Tier Architecture Human Resource Management System with Java
Stars: ✭ 32 (+10.34%)
Mutual labels:  cloudinary
spring-boot-react-ecommerce-app
eCommerce application based on the microservices architecture built using Spring Boot and ReactJS.
Stars: ✭ 221 (+662.07%)
Mutual labels:  cloudinary
auto-cloudinary
Super simple Cloudinary auto-upload implementation for WordPress.
Stars: ✭ 34 (+17.24%)
Mutual labels:  cloudinary
axiom
Axiom - A Hugo Theme. GitTip: https://gitcoin.co/tip?username=jhauraw
Stars: ✭ 67 (+131.03%)
Mutual labels:  cloudinary
apollo-instagram-clone
Apollogram | A place where you could share photos, like media, and follow peoples.
Stars: ✭ 24 (-17.24%)
Mutual labels:  cloudinary
nodejs-guitarstore
A Guitar WebStore using Nodejs Mongodb and Javascript Technologies
Stars: ✭ 19 (-34.48%)
Mutual labels:  cloudinary
HumanResources
Account Registration and Confirmation. Exception Handling. Caching with Redis.Mail sender by Apache Kafka.Notification send with RabbitMq.
Stars: ✭ 19 (-34.48%)
Mutual labels:  cloudinary
shrine-cloudinary
Cloudinary storage for Shrine
Stars: ✭ 23 (-20.69%)
Mutual labels:  cloudinary
cloudinary-api
Shorter and lighter APIs for Cloudinary
Stars: ✭ 41 (+41.38%)
Mutual labels:  cloudinary

Cloudinary Tiny JS

Cloudinary is a cloud service that offers a solution to a web application's entire image management pipeline. For client-side image management Cloudinary provides the cloudinary-core library for conveniently compiling transform options to asset URLs. The problem is that it's a massive library often used to simply convert an object of properties to a string.

cloudinary-tiny-js provides the same commonly used image transformation features at a fraction of the size and without any dependencies.

Video transformations are not currently supported nor are some advanced configuration options. It may also fall short on some advanced image transformations. If you need this functionality, please submit PRs with references to the relevant Cloudinary documentation.

Usage

Basic configuration

The default export is a configuration function returning another function for building Cloudinary URLs. Configuration option names follow the documentation on Transforming media assets using dynamic URLs and Private CDNs and CNAMEs . Only the cloudName is required. Defaults are shown below.

import cloudinary from 'cloudinary-tiny-js'

const cl = cloudinary({
  /** The name of your Cloudinary account, a unique public identifier for URL building and API access. */
  cloudName: 'demo',
  /**
   * The type of asset to deliver, `image` by default. Valid values: `image`, `raw`, or `video`.
   * Only the `image` type currently supports transforms.
   */
  assetType: 'image',
  /**
   * The storage or delivery type. Default: upload. For details on all possible types, see the
   * Cloudinary docs on delivery types.
   */
  deliveryType: 'upload',
  /** Use https instead of http */
  secure: true,
  /** Override the subdomain when using a private CDN distribution. */
  cdnSubdomain: 'res',
  /** A fully customisable CNAME. */
  cname: 'res.cloudinary.com',
  /** Transforms applied to all images, any transforms passed later will extend these defaults. */
  imageTransformDefaults: { quality: 'auto' /* Any valid transforms, see below */ },
})

const imageUrl = cl('sample.png', { width: 150 })
expect(imageUrl).toBe('https://res.cloudinary.com/demo/image/upload/q_auto,w_150/sample.png')

Image transformations

All image transformations documented in the Transformation URL API reference are supported except for arithmetic operators, conditionals and variables.

To create a resource URL, call the function returned by the configuration function with a public ID and optional image transformation options:

const basicUrl = cl('sample.png')
expect(basicUrl).toBe('https://res.cloudinary.com/demo/image/upload/v1/sample.png')

const resizedUrl = cl('sample.png', { width: 150, height: 100 })
expect(resizedUrl).toBe('https://res.cloudinary.com/demo/image/upload/w_150,h_100/v1/sample.png')

Other options that can be provided alongside transform options are:

const url = cl('http://example.com/sample.dat', {
  /**
   * Specify a single or multiple transformations to apply. The options of a single transform can also
   * be included directly on this parent object. Note that the default transforms are only applied
   * when a single transform is provided and not for an array of transforms.
   */
  transformations: undefined,
  /**
   * Override the `assetType` provided in the configuration.
   */
  assetType: 'raw',
  /**
   * Override the `deliveryType` provided in the configuration.
   */
  deliveryType: 'fetch',
  /**
   * You can add the version to your delivery URL to bypass the cached version on the CDN and
   * force delivery of the latest resource. As an alternative to using versions, you can set the
   * `invalidate` parameter to true while uploading a new image in order to invalidate the
   * previous image throughout the CDN.
   */
  version: 742,
})
expect(url).toBe('http://res.cloudinary.com/demo/raw/fetch/v742/http://example.com/sample.dat')

To perform multiple transformations an array of transform objects can be passed; the array can be passed directly as the second parameter or on the transformations property along with other options.

This will generate the URL of the first example in the Image transformation reference:

const transformations = [
  { width: 220, height: 140, crop: 'fill' },
  { overlay: 'brown_sheep', width: 220, height: 140, x: 220, crop: 'fill' },
  { overlay: 'horses', width: 220, height: 140, x: -110, y: 140, crop: 'fill' },
  { overlay: 'white_chicken', width: 220, height: 140, x: 110, y: 70, crop: 'fill' },
  { overlay: 'butterfly.png', height: 200, x: -10, angle: 10 },
  { width: 400, height: 260, radius: 20, crop: 'crop' },
  { overlay: 'text:Parisienne_35_bold:Memories%20from%20our%20trip', color: '#990C47', y: 155 },
  { effect: 'shadow' },
]

const url = cl('yellow_tulip.jpg', transformations)

// Or with other options
const url = cl('yellow_tulip.jpg', {
  version: 423,
  transformations,
})

Specifying default image transformations

The imageTransformDefaults property provides a convenient way to include certain transform options in all image transforms. For example, specifying auto format, quality and width for all images can be achieved by passing:

const cl = cloudinary({
  cloudName: 'demo',
  imageTransformDefaults: {
    format: 'auto',
    quality: 'auto',
    width: 'auto',
  },
})

const imageUrl = cl('sample.png', { aspectRatio: '16:9' })
expect(imageUrl).toBe('https://res.cloudina.../f_auto,q_auto,w_auto,ar_16:9/v1/sample.png')

Override any default value by passing a replacement value or remove it from the URL by passing undefined:

const cl = cloudinary({
  cloudName: 'demo',
  imageTransformDefaults: {
    format: 'auto',
    quality: 'auto',
    width: 'auto',
  },
})

const imageUrl = cl('sample.png', { aspectRatio: '16:9', width: 150, quality: undefined })
expect(imageUrl).toBe('https://res.cloudina.../f_auto,ar_16:9,w_150/v1/sample.png')

Transformation parameter validation

Typings should help to provide valid parameter values in most cases, but errors will also be thrown on invalid parameter values in development, for example:

cl('sample.jpg', { radius: 'round' })
// Throws:
// Cloudinary Image :: radius should be a number, 'max' or have the form x[:y[:z[:u]]], received: 'round'

Some exceptions are the effect, overlay and underlay values which are not validated.

Building for production

When building for production ensure process.env.NODE_ENV === 'production' so the validation logic can be removed from the bundle during minification.

Contributing

The most important configuration and image transformation features of Cloudinary should be supported, but if anything is missing please submit issues or PRs with references to the relevant Cloudinary documentation.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].