npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ng-jcrop

v2.2.1

Published

ng-jcrop

Downloads

213

Readme

Build Status Coverage Status Code Climate David dm

ng-jcrop

Angular directive to jCrop jQuery plugin

Demo

http://andrefarzat.github.io/ng-jcrop/

Installing

Install via bower or npm

bower install ng-jcrop --save
# or
npm install ng-jcrop --save

It depends of angular, jquery and jquery-jcrop, so it is necessary including all libraries

<link rel="stylesheet" href="bower_components/jcrop/css/jquery.Jcrop.css" />

<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/jcrop/js/jquery.Jcrop.js"></script>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/ng-jcrop/ng-jcrop.js"></script>

Usage

// add 'ngJcrop' as dependency to your module
var yourModule = angular.module("yourModule", ['ngJcrop']);

And add the ng-jcrop directive in an <div> giving the image's src as the value

<script>

var app = angular.module('yourModule', ['ngJcrop']);

// Optional configuration via ngJcropConfigProvider
app.config(function(ngJcropConfigProvider){

    // [optional] To change the jcrop configuration
    // All jcrop settings are in: http://deepliquid.com/content/Jcrop_Manual.html#Setting_Options
    ngJcropConfigProvider.setJcropConfig({
        bgColor: 'black',
        bgOpacity: .4,
        aspectRatio: 16 / 9
    });

    // [optional] A configuration can have a name as its first parameter,
    // so you can have multiple configurations in the same app
    ngJcropConfigProvider.setJcropConfig('anotherConfig', {
        bgColor: 'white',
        bgOpacity: .2,
        aspectRatio: 4 / 3
    });

    // [optional] To change the css style in the preview image
    ngJcropConfigProvider.setPreviewStyle({
        'width': '100px',
        'height': '100px',
        'overflow': 'hidden',
        'margin-left': '5px'
    });

});

app.controller('SomeController', function($scope){
    $scope.obj = {}

    // The url or the data64 for the image
    $scope.obj.src = 'beautifulImage.jpg';

    // Required: The current selection coords. Must be [x, y, x2, y2, w, h]
    $scope.obj.selection = [100, 100, 200, 200, 100, 100];

    // Optional: The coords of the selection related to the screen.
    // Use this to debug or in case you need to store the current "screen" value to replicate the same selection later
    $scope.obj.coords = [];

    // You can add a thumbnail if you want
    $scope.obj.thumbnail = true;
});
</script>

<!-- Using the default configuration -->
<div ng-jcrop="obj.src" selection="obj.selection" thumbnail="obj.thumbnail"></div>

<!-- Using configuration name 'anotherConfig' -->
<div ng-jcrop="obj.src" ng-jcrop-config-name="anotherConfig" selection="obj.selection" thumbnail="obj.thumbnail"></div>

Testing

It is necessary install karma and its dependencies

npm install

Then you can run the tests

npm test

Starting the demo page

It is necessary install the http-server

npm install

Then you run npm start and access http://localhost:8080/demo/

FAQ

1. How to get the source of a selected image? (related issue: #37)

Once the user selects an image, the $rootScope broadcasts the JcropChangeSrc event passing the image (as dataURL) and the configName. Example:

$scope.$on('JcropChangeSrc', function(ev, src, configName){
    $scope.imageSrc = src; // the image as dataURL
});

ng-jcrop uses FileReader.readAsDataURL to load the image.

2. How to get the real coords to replicate the selection? (related issue: #64)

It was added the coords attribute to make it possible to access the "real" coords of the selection. "Real" means the selection coords you see on the screen NOT the selection coords which is in selection attribute which is the coords already with the aspect ratio computed.

Use like this to access the coords:

<div ng-jcrop="obj.src" selection="obj.selection" thumbnail="obj.thumbnail" coords="obj.coords"></div>

You can see a better example at the demo page