### Install @transform-in/sdk
Source: https://github.com/transform-in-net/javascript-sdk/blob/main/README.md
Instructions for installing the TRANSFORM.IN JavaScript SDK using npm, yarn, or pnpm package managers.
```bash
# Using npm
npm install @transform-in/sdk
# Using yarn
yarn add @transform-in/sdk
# Using pnpm
pnpm add @transform-in/sdk
```
--------------------------------
### Development Commands (npm)
Source: https://github.com/transform-in-net/javascript-sdk/blob/main/README.md
Provides common npm commands for developing with the Transform.in JavaScript SDK. These include installing dependencies, running automated tests, and building the project for distribution.
```bash
# Install dependencies
npm install
# Run tests
npm test
# Build the SDK
npm run build
```
--------------------------------
### Get Image Information
Source: https://github.com/transform-in-net/javascript-sdk/blob/main/README.md
Retrieves detailed information about an image from a given URL. Returns success status and data including type, dimensions, and size.
```javascript
const info = await transformIn.info('https://example.com/image.jpg');
if (info.success) {
console.log(info.data);
// {
// base64: 'encoded-url',
// url: 'https://example.com/image.jpg',
// type: 'image',
// ext: 'jpg',
// content_type: 'image/jpeg',
// width: 1200,
// height: 800,
// size: 123456
// }
}
```
--------------------------------
### Initialize TransformIn SDK
Source: https://github.com/transform-in-net/javascript-sdk/blob/main/README.md
Demonstrates how to import and initialize the TransformIn SDK with API key and project ID. Supports optional custom base URLs.
```javascript
import TransformIn from '@transform-in/sdk';
const transformIn = new TransformIn({
api_key: 'your-api-key',
project_id: 'your-project-id',
// Optional: custom base URL
// base_url: 'https://custom-api.example.com'
});
```
--------------------------------
### Prepare Video Transformation (Async)
Source: https://github.com/transform-in-net/javascript-sdk/blob/main/README.md
Initiates a video transformation process asynchronously. It's recommended for larger videos to use this approach and check status later.
```javascript
// Video transformations are typically processed asynchronously
const videoPreparation = await transformIn.prepareTransformation(
'https://example.com/video.mp4',
{
w: 640,
h: 360,
f: 'mp4',
q: 80
}
);
if (videoPreparation.success) {
console.log(videoPreparation.data.message); // "Transformation is being processed"
}
// For larger videos, it's recommended to use the asynchronous approach
// and check the status later rather than waiting for completion
```
--------------------------------
### Prepare Image Transformation (Async)
Source: https://github.com/transform-in-net/javascript-sdk/blob/main/README.md
Initiates an image transformation process asynchronously without waiting for completion. Optionally, can wait for completion by passing 'true' as the third argument.
```javascript
// Trigger transformation without waiting for completion
const preparation = await transformIn.prepareTransformation(
'https://example.com/image.jpg',
{
w: 300,
h: 200,
f: 'webp',
q: 80
}
);
if (preparation.success) {
console.log(preparation.data.message); // "Transformation is being processed"
}
// Or wait for the transformation to complete
const completedPreparation = await transformIn.prepareTransformation(
'https://example.com/image.jpg',
{
w: 300,
h: 200,
f: 'webp',
q: 80
},
true // Set to true to wait for completion
);
if (completedPreparation.success) {
console.log(completedPreparation.data.message); // "Transformation processed"
}
```
--------------------------------
### Generate Image Transformation URL
Source: https://github.com/transform-in-net/javascript-sdk/blob/main/README.md
Creates a URL for transforming an image with specified parameters like width, height, format, quality, and blur.
```javascript
const transformationUrl = transformIn.url('https://example.com/image.jpg', {
w: 300, // Width
h: 200, // Height
f: 'webp', // Format
q: 80, // Quality (1-100)
bl: 5 // Blur
});
// Use this URL in your
tags or for direct access
console.log(transformationUrl);
// https://api.transform.in.net/transformation/your-project-id/your-api-key/encoded-url/w:300,h:200,f:webp,q:80,bl:5
```
--------------------------------
### Generate Video Transformation URL
Source: https://github.com/transform-in-net/javascript-sdk/blob/main/README.md
Creates a URL for transforming a video, specifying parameters like width, height, format (MP4), and quality.
```javascript
const videoTransformationUrl = transformIn.url('https://example.com/video.mp4', {
w: 640, // Width
h: 360, // Height
f: 'mp4', // Format (currently only mp4 is supported for video)
q: 80 // Quality (1-100)
});
// Use this URL in your