Tips for stretching the default crop section in ngimgcrop angular

Is there a way to make the crop area of ngimgcrop stretch to the fullest width of the image? I would like the crop portion to automatically stretch to the full width or height when selected.

Here is a screenshot demonstrating exactly what I am looking for:

https://i.sstatic.net/nVC5i.png

I have attempted to achieve this using ng-img-crop.js but have not found a solution yet.

angular.module('app', ['ngImgCrop'])
.controller('Ctrl', function($scope) {
  $scope.myImage='';
  $scope.myCroppedImage='';

  var handleFileSelect=function(evt) {
    var file=evt.currentTarget.files[0];
    var reader = new FileReader();
    reader.onload = function (evt) {
      $scope.$apply(function($scope){
        $scope.myImage=evt.target.result;
      });
    };
    reader.readAsDataURL(file);
  };
  angular.element(document.querySelector('#fileInput')).on('change',handleFileSelect);
});
.cropArea {
  background: #E4E4E4;
  overflow: hidden;
  width:500px;
  height:350px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://cdn.rawgit.com/alexk111/ngImgCrop/master/compile/minified/ng-img-crop.js"></script>
<link href="https://cdn.rawgit.com/alexk111/ngImgCrop/master/compile/minified/ng-img-crop.css" rel="stylesheet" />

<body ng-app="app" ng-controller="Ctrl">
  <div>Select an image file: <input type="file" id="fileInput" /></div>
  <div class="cropArea">
    <img-crop image="myImage" result-image="myCroppedImage" area-type="square" result-image-format="image/jpeg" area-min-size="150"></img-crop>
  </div>
  <div>Cropped Image:</div>
  <div><img ng-src="{{myCroppedImage}}" /></div>
</body>

http://jsfiddle.net/rw6q9/2579/

Answer №1

I regret to inform you that this feature is not available with the current plugin. Unfortunately, it only allows for cropping a square area, which means setting the area as full width and height may not be possible in most cases.

To achieve this functionality, you can utilize ngCropper - an Angular module based on the popular jQuery plugin cropper.

The ngCropper plugin offers a wider range of options, allowing you to customize it according to your specific requirements.

You can see an example implementation below (View it in Full page mode or in the bin):

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Storing a temporary value within an ng-repeat iteration in AngularJS

A unique and interesting query arises when dealing with random value generation. Here is a snippet of code that showcases how to achieve this: function randomize() { return function (input) { if (input !== null && input !== undefined & ...

The RSS feed reader is currently malfunctioning

I'm having trouble loading an RSS feed from the following URL: http://solutions.astrology.com/scripts/it.dll?cust_id=aamfha&doc=daily07short/dailyshort.xml Here is the code I am using to try to read it: url = 'http://solutions.astrology.co ...

What is the best way to extract JSON data from text using node.js?

Currently, I am attempting to convert an html response into JSON format for easier access. This is the code snippet for my router: router.get('/yammer', function(req, res) { var userFields; var yammerCode = req.query.code; var getYammerFi ...

Preventing the default behavior using event.preventDefault() does not seem to be effective when submitting a

Why is the event.preventDefault() method not functioning properly? <script type="text/javascript" src="vue.js"></script> <div id="app"> <form v-on:submit.prevent="saveData"> <input type="text" name="test"> <button ...

What is the method to create a number using a textbox through javascript?

Whenever a number is entered into the main_textbox, a JavaScript function is called on the onblur event of the textbox using the following code: function generate_bale(){ var bale=document.getElementById("number_of_bale").value; var boxes = "< ...

Firefox exhibiting an additional pixel when hovering over dropdown menus

When using top: 100% to position a sub-menu dropdown below the main navigation bar on hover, there seems to be an issue in Firefox where the menu is pushed below the border of the menu causing a small gap. Interestingly, this works as expected in Webkit br ...

Adjust the height of a div using jQuery

I'm attempting to dynamically adjust the height of a div based on the height of a table. Here is my code : <div> <table class="responsive"> <tbody> <tr> <th>Ref</th> ...

Quick way to access dropdown menu in Visual Code while selecting JavaScript/React code

While working on React code in Visual Studio Code, I accidentally triggered a dropdown menu when trying to copy and paste a section of my code. One of the items that caught my eye was labeled "Destructure JavaScript," which seemed intriguing. Unfortunately ...

The model is failing to load in the three.js environment

After spending the entire day experimenting with different solutions, I am still unable to solve my problem. Despite trying various examples from previous years, my objects are not appearing as expected. I have experimented with three different formats: . ...

Exploring z-indices in event bubbling

JSFiddle: https://jsfiddle.net/uLap7yeq/19/ Issue Let's examine a scenario where there are two elements, canvas and div, positioned in the same location using CSS. The div has a higher z-index compared to the canvas, but how can we make sure events ...

Error in package: Module 'tslib' not found

After two days of troubleshooting, I am still unable to pinpoint the issue at hand. The packages installed on my system include: node-sass, autoprefixer, parcel-bundler, and parcel-plugin-pug. My entry point is an index.pug file with relative links to .scs ...

Center a Bootstrap 4 card both vertically and horizontally without overflowing the screen

I am facing an issue with a single page layout where I have a centrally positioned card containing a form and text. Once the form is submitted, a list is displayed. However, sometimes the list is lengthy causing the card to cut off at the top with no scrol ...

Tips for adjusting the text color of input fields while scrolling down

I am currently working on my website which features a search box at the top of every page in white color. I am interested in changing the color of the search box to match the background color of each individual page. Each page has its own unique background ...

What's the best way to get rid of the one-pixel gap between these elements on high-resolution displays like

http://jsfiddle.net/36ykrp9x/5/ HTML <div class="container"> <button>O</button><button>O</button> </div> CSS .container { width: 100%; background-color: rgb(120, 200, 200); text-align: center; } butt ...

Styling the center menu

Is there a way to horizontally center this top menu using CSS? https://i.sstatic.net/9yvJf.png This is the HTML structure I am working with: <div class="wrapper_menu_hoz"> <div class="container_24 "> <div class="gr ...

Replace pipeline function during component testing

During my unit testing of a component that utilizes a custom pipe, I encountered the need to provide a fake implementation for the transform method in my test. While exploring options, I discovered that it's feasible to override components, modules, ...

Utilize JavaScript to retrieve data from a JSON document

To extract information from a .json file in node.js, the require function is used. I'm currently developing an Artificial Neural Network that utilizes this code to fetch data from the data.json file. const fs = require('fs'); const json = ...

Display a popup in Angular 4 when a click event is triggered by a separate

I am currently facing an issue that I can't seem to solve. My objective is to display a popup div on the page when clicking on a menu entry in my navbar.component. In order to achieve this, I introduced a property called "show" in my popup component ...

PHP query Ajax navigation

UPDATED I have made progress with processing both menus in "process.php" and displaying the queries in index.php. process.php <?php $menu1 = $_POST["menu1"]; $menu2 = $_POST["menu2"]; if($menu1 == 0) { $sql = "SELECT * FROM Language WHERE ID = " ...

limitations on passing url parameters in react.js

Currently, I am facing an issue with passing URL parameters in my React.js web app. For illustration purposes, here is a snippet of the routes: import React from "react"; import {BrowserRouter, Route, Switch, Redirect} from 'react-router-dom'; ...