Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mobimedia/core

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mobimedia/core

Optimize your images on the fly with MobiMedia.ai. This is a SDK for converting and appending image optimiztion parameters to the image src making it optimized as per the client devices.

  • 0.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@mobimedia/core

Optimize your images on the fly with MobiMedia.ai. This is a SDK for converting and appending image optimization parameters to the image src making it optimized as per the client devices.

Installation

npm install @mobimedia/core

Usage for S3

import { MobiMediaConfig } from "@mobimedia/core";

const s3Transformer = MobiMediaConfig("test.mobimedia.ai")
const src = s3Transformer.url("https://s3HostedMedia.mydomain.com/test.png", {
  w: 100,
});
// => https://test.mobimedia.ai/test.png?quality=70&format=webp&w=100

Usage for Cloudinary URL Conversion to S3

import { MobiMediaConfig } from "@mobimedia/core";

const s3 = MobiMediaConfig('test.mobimedia.ai', {
  s3PublicUrl: 'https://s3HostedMedia.mydomain.com',
  s3CloudinaryPath: '/cloudinary/res/cloudName/image/upload',
});

const src = s3.url(
  'https://cloudinaryHostedMedia.mydomain.com/cloudName/image/upload/c_fill,f_auto,g_auto,w_640/v1674128459/test/test.jpg',
  {
    w: 100,
  }
);
// => https://test.mobimedia.ai/cloudinary/res/cloudName/image/upload/test/test/1674128459.jpg?quality=70&format=webp&w=100

MobiMediaConfig Options

The MobiMediaConfig function provides options for configuring the MobiMedia.ai image optimization service. It takes the following parameters:

subDomain (required)

Type: string

The subDomain parameter is a required string that represents the subdomain of the MobiMedia.ai service. This is a crucial configuration as it defines the specific MobiMedia.ai instance to be used for image optimization.

convertCloudinaryToS3Url (optional)

Type: { s3PublicUrl: string, s3CloudinaryPath: string }

Default: { s3PublicUrl: '', s3CloudinaryPath: '' }

The convertCloudinaryToS3Url parameter is an optional object that allows configuring settings related to converting Cloudinary URLs to S3 URLs. It has the following properties:

  • s3PublicUrl: A string representing the public URL of the S3 bucket where the images will be stored.

  • s3CloudinaryPath: A string representing the path within the S3 bucket where the converted images will be stored.

Image url Supported Options

URL ArgTypeDescription
wNumberMax width of the image.
hNumberMax height of the image.
qualityNumber, 0-100Image quality.
resizeString, "w,h"A comma separated string of the target width and height in pixels. Crops the image.
crop_strategyString, "smart", "entropy", "attention"There are 3 automatic cropping strategies for use with resize:
  • attention: good results, ~70% slower
  • entropy: mediocre results, ~30% slower
  • smart: best results, ~50% slower
gravityStringAlternative to crop_strategy. Crops are made from the center of the image by default, passing one of "north", "northeast", "east", "southeast", "south", "southwest", "west", "northwest" or "center" will crop from that edge.
fitString, "w,h"A comma separated string of the target maximum width and height. Does not crop the image.
cropBoolean|String, "x,y,w,h"Crop an image by percentages x-offset, y-offset, width and height (x,y,w,h). Percentages are used so that you don’t need to recalculate the cropping when transforming the image in other ways such as resizing it. You can crop by pixel values too by appending px to the values. crop=160px,160px,788px,788px takes a 788 by 788 pixel square starting at 160 by 160.
zoomNumberZooms the image by the specified amount for high DPI displays. zoom=2 produces an image twice the size specified in w, h, fit or resize. The quality is automatically reduced to keep file sizes roughly equivalent to the non-zoomed image unless the quality argument is passed.
webpBoolean, 1Load WebP format.
lbString, "w,h"Add letterboxing effect to images, by scaling them to width, height while maintaining the aspect ratio and filling the rest with black or background.
backgroundStringAdd background color via name (red) or hex value (%23ff0000). Don't forget to escape # as %23.

Feel free to raise any issues on our Github Issues page if you find any.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Keywords

FAQs

Package last updated on 14 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc