All Projects → third774 → Image Focus

third774 / Image Focus

Licence: mit
A dependency free utility for cropping images based on a focus point ~2.13kB gzipped

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Image Focus

Cropme
Extremely Smooth and Easy Cropping library for you
Stars: ✭ 306 (+128.36%)
Mutual labels:  image, cropper, cropping
Tocropviewcontroller
A view controller for iOS that allows users to crop portions of UIImage objects
Stars: ✭ 4,210 (+3041.79%)
Mutual labels:  image, cropper, cropping
Rskimagecropper
An image cropper / photo cropper for iOS like in the Contacts app with support for landscape orientation.
Stars: ✭ 2,371 (+1669.4%)
Mutual labels:  image, cropper, cropping
Guillotine
jQuery plugin to crop images within an area (fully responsive), allowing to drag (touch support), zoom and rotate.
Stars: ✭ 318 (+137.31%)
Mutual labels:  image, responsive
Croppr.js
A vanilla JavaScript image cropper that's lightweight, awesome, and has absolutely zero dependencies.
Stars: ✭ 294 (+119.4%)
Mutual labels:  image, cropper
React Native Scalable Image
React Native Image component which scales width or height automatically to keep the original aspect ratio
Stars: ✭ 241 (+79.85%)
Mutual labels:  image, responsive
Android Imagecropview
android image crop library
Stars: ✭ 225 (+67.91%)
Mutual labels:  image, cropping
Glightbox
Pure Javascript lightbox with mobile support. It can handle images, videos with autoplay, inline content and iframes
Stars: ✭ 702 (+423.88%)
Mutual labels:  image, responsive
React Native Fit Image
Responsive image component to fit perfectly itself.
Stars: ✭ 539 (+302.24%)
Mutual labels:  image, responsive
Image Cropper
💯一款功能强大的微信小程序图片裁剪插件
Stars: ✭ 893 (+566.42%)
Mutual labels:  image, cropper
Imgviewer
jQuery plugin to zoom and pan images, even those with a size that is a percentage of their container
Stars: ✭ 50 (-62.69%)
Mutual labels:  image, responsive
react-native-avatar-crop
Highly customisable <Crop /> component for React Native < 💅 >
Stars: ✭ 47 (-64.93%)
Mutual labels:  cropper, cropping
Vue Product Zoomer
Zoom Prodct Image, useful for e-shop website
Stars: ✭ 248 (+85.07%)
Mutual labels:  image, responsive
React Responsive Image
🖼️ A React responsive image component.
Stars: ✭ 36 (-73.13%)
Mutual labels:  image, responsive
Jekyll Cloudinary
Jekyll plugin adding a Liquid tag for Cloudinary, for better responsive images
Stars: ✭ 79 (-41.04%)
Mutual labels:  image, responsive
React Native Image Crop Picker
iOS/Android image picker with support for camera, video, configurable compression, multiple images and cropping
Stars: ✭ 5,261 (+3826.12%)
Mutual labels:  image, cropping
React Responsive Picture
A future-proof responsive image component that supports latest Picture specification
Stars: ✭ 91 (-32.09%)
Mutual labels:  image, responsive
Igrphototweaks
Drag, Rotate, Scale and Crop
Stars: ✭ 212 (+58.21%)
Mutual labels:  image, cropping
Kirby Autofocus
Content aware image cropping for Kirby. Kirby 2 and 3.
Stars: ✭ 35 (-73.88%)
Mutual labels:  image, focus
Angular Cropperjs
CropperJS integration for Angular +6
Stars: ✭ 88 (-34.33%)
Mutual labels:  image, cropper

image-focus 📷

A dependency free utility for cropping images based on a focus point ~2.13kB gzipped

npm version npm downloads MIT

Demo

Demo

Check out the demo and then play with editing it

Docs

Docs generated by typedoc

Usage

Focus Coordinates range between -1 and 1 for both x and y axes. The FocusPicker class will help enable users to select the focus point to be used with an image.

FocusedImage

There are two ways to supply the coordinates when initializing the FocusedImage class

Data Tags

<div class="focused-image-container">
  <img class="focused-image" src="https://picsum.photos/2400/1400" data-focus-x="0.34" data-focus-y="-0.21">
</div>
import { FocusedImage } from "image-focus"

const img = document.querySelector('.focused-image') as HTMLImageElement
const focusedImage = new FocusedImage(img)

Using focus Option

<div class="focused-image-container">
  <img class="focused-image" src="https://picsum.photos/2400/1400">
</div>
import { FocusedImage } from "image-focus"

const img = document.querySelector('.focused-image') as HTMLImageElement
const focusedImage = new FocusedImage(img, {
  focus: {
    x: 0.34,
    y: -0.21
  }
})

FocusPicker

Provide an onChange callback that will receive a Focus object that has x and y properties for the newly selected coordinates. Optionally supply a focus to initialize with, or a retina src to use instead of the default white ring SVG.

import {FocusedImage, FocusPicker} from "image-focus"

const imgEl = document.getElementById("focused-image") as HTMLImageElement
const focusedImage = new FocusedImage(imgEl)

const focusPickerEl = document.getElementById("focus-picker-img") as HTMLImageElement
const focusPicker = new FocusPicker(focusPickerEl, {
  onChange: focus => focusedImage.setFocus(focus),
  focus: startingFocus,
})

What's going on?

The <img/> element is being set to position: absolute; and having its top and left properties adjusted based on some calculations using the image and parent containers' aspect ratios and dimensions. The <img/>'s parent container gets set to position: relative; and overflow: hidden; to create the effect. There are a few other inline styles that get applied, so if anything appears to be behaving unexpectedly, be sure to check that the inline styles on both the <img/> and its parent aren't being overridden by CSS on your page (especially from rules using !important).

Additionally, because the FocusedImage is positioned absolutely so it can shift as needed, its container needs to manage its own height and width. If you aren't seeing an image appear at all, it is likely that the parent div's height is fully collapsed.

What if I'm not using npm and a build process?

That's okay! unpkg has you covered. Just add this script tag to your page and the image-focus module is exposed in the global namespace under window.imageFocus.

<script src="https://unpkg.com/[email protected]"></script>

Then in some script that loads after the above script tag:

var imgEl = document.querySelector('img.focused-image');
var focusedImage = new imageFocus.FocusedImage(imgEl, {x: 0.25, y: -0.3});

Attributions

This project was largely inspired by and adapted from jquery-focuspoint by jonom and used typescript-library-starter to scaffold the build process.

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].