Skip to content

Commit

Permalink
Added sourceWidth, sourceHeight, top, right, bottom and left options …
Browse files Browse the repository at this point in the history
…to allow arbitrary cropping. Closes blueimp#31

Moved orientation functionality into a separate file.
Added the Jcrop plugin to the demo to visualize the new cropping
features.
  • Loading branch information
blueimp committed Jul 12, 2013
1 parent 2685792 commit c1b88ae
Show file tree
Hide file tree
Showing 15 changed files with 2,251 additions and 115 deletions.
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
.PHONY: js

MINIFY_LIST=js/load-image.js js/load-image-ios.js js/load-image-meta.js js/load-image-exif.js js/load-image-exif-map.js
MINIFY=js/load-image.js
MINIFY+= js/load-image-ios.js
MINIFY+= js/load-image-orientation.js
MINIFY+= js/load-image-meta.js
MINIFY+= js/load-image-exif.js
MINIFY+= js/load-image-exif-map.js

js:
node_modules/.bin/uglifyjs ${MINIFY_LIST} -c -m -o js/load-image.min.js
node_modules/.bin/uglifyjs ${MINIFY} -c -m -o js/load-image.min.js
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Or alternatively, choose which components you want to include:
```html
<script src="js/load-image.js"></script>
<script src="js/load-image-ios.js"></script>
<script src="js/load-image-orientation.js"></script>
<script src="js/load-image-meta.js"></script>
<script src="js/load-image-exif.js"></script>
<script src="js/load-image-exif-map.js"></script>
Expand Down Expand Up @@ -117,6 +118,18 @@ The optional third argument to **loadImage()** is a map of options:
* **maxHeight**: Defines the maximum height of the img/canvas element.
* **minWidth**: Defines the minimum width of the img/canvas element.
* **minHeight**: Defines the minimum height of the img/canvas element.
* **sourceWidth**: The width of the sub-rectangle of the source image to draw into the destination canvas.
Defaults to the source image width and requires *canvas: true*.
* **sourceHeight**: The height of the sub-rectangle of the source image to draw into the destination canvas.
Defaults to the source image height and requires *canvas: true*.
* **top**: The top margin of the sub-rectangle of the source image.
Defaults to *0* and requires *canvas: true*.
* **right**: The right margin of the sub-rectangle of the source image.
Defaults to *0* and requires *canvas: true*.
* **bottom**: The bottom margin of the sub-rectangle of the source image.
Defaults to *0* and requires *canvas: true*.
* **left**: The left margin of the sub-rectangle of the source image.
Defaults to *0* and requires *canvas: true*.
* **contain**: Scales the image up/down to contain it in the max dimensions if set to *true*.
This emulates the CSS feature [background-image: contain](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Scaling_background_images#contain).
* **cover**: Scales the image up/down to cover the max dimensions with the image dimensions if set to *true*.
Expand Down
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blueimp-load-image",
"version": "1.8.0",
"version": "1.9.0",
"title": "JavaScript Load Image",
"description": "JavaScript Load Image is a library to load images provided as File or Blob objects or via URL. It returns an optionally scaled and/or cropped HTML img or canvas element. It also provides a method to parse image meta data to extract Exif tags and thumbnails and to restore the complete image header after resizing.",
"keywords": [
Expand Down Expand Up @@ -48,6 +48,7 @@
"main": [
"./js/load-image.js",
"./js/load-image-ios.js",
"./js/load-image-orientation.js",
"./js/load-image-meta.js",
"./js/load-image-exif.js",
"./js/load-image-exif-map.js"
Expand Down
5 changes: 4 additions & 1 deletion css/demo.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* JavaScript Load Image Demo CSS 1.8.0
* JavaScript Load Image Demo CSS 1.9.0
* https://github.com/blueimp/JavaScript-Load-Image
*
* Copyright 2013, Sebastian Tschan
Expand Down Expand Up @@ -56,6 +56,9 @@ td {
color: #222;
text-align: center;
}
.jcrop-holder {
margin: 0 auto;
}

@media (min-width: 481px) {
.navigation {
Expand Down
Binary file added css/vendor/Jcrop.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
165 changes: 165 additions & 0 deletions css/vendor/jquery.Jcrop.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/* jquery.Jcrop.css v0.9.12 - MIT License */
/*
The outer-most container in a typical Jcrop instance
If you are having difficulty with formatting related to styles
on a parent element, place any fixes here or in a like selector
You can also style this element if you want to add a border, etc
A better method for styling can be seen below with .jcrop-light
(Add a class to the holder and style elements for that extended class)
*/
.jcrop-holder {
direction: ltr;
text-align: left;
}
/* Selection Border */
.jcrop-vline,
.jcrop-hline {
background: #ffffff url("Jcrop.gif");
font-size: 0;
position: absolute;
}
.jcrop-vline {
height: 100%;
width: 1px !important;
}
.jcrop-vline.right {
right: 0;
}
.jcrop-hline {
height: 1px !important;
width: 100%;
}
.jcrop-hline.bottom {
bottom: 0;
}
/* Invisible click targets */
.jcrop-tracker {
height: 100%;
width: 100%;
/* "turn off" link highlight */
-webkit-tap-highlight-color: transparent;
/* disable callout, image save panel */
-webkit-touch-callout: none;
/* disable cut copy paste */
-webkit-user-select: none;
}
/* Selection Handles */
.jcrop-handle {
background-color: #333333;
border: 1px #eeeeee solid;
width: 7px;
height: 7px;
font-size: 1px;
}
.jcrop-handle.ord-n {
left: 50%;
margin-left: -4px;
margin-top: -4px;
top: 0;
}
.jcrop-handle.ord-s {
bottom: 0;
left: 50%;
margin-bottom: -4px;
margin-left: -4px;
}
.jcrop-handle.ord-e {
margin-right: -4px;
margin-top: -4px;
right: 0;
top: 50%;
}
.jcrop-handle.ord-w {
left: 0;
margin-left: -4px;
margin-top: -4px;
top: 50%;
}
.jcrop-handle.ord-nw {
left: 0;
margin-left: -4px;
margin-top: -4px;
top: 0;
}
.jcrop-handle.ord-ne {
margin-right: -4px;
margin-top: -4px;
right: 0;
top: 0;
}
.jcrop-handle.ord-se {
bottom: 0;
margin-bottom: -4px;
margin-right: -4px;
right: 0;
}
.jcrop-handle.ord-sw {
bottom: 0;
left: 0;
margin-bottom: -4px;
margin-left: -4px;
}
/* Dragbars */
.jcrop-dragbar.ord-n,
.jcrop-dragbar.ord-s {
height: 7px;
width: 100%;
}
.jcrop-dragbar.ord-e,
.jcrop-dragbar.ord-w {
height: 100%;
width: 7px;
}
.jcrop-dragbar.ord-n {
margin-top: -4px;
}
.jcrop-dragbar.ord-s {
bottom: 0;
margin-bottom: -4px;
}
.jcrop-dragbar.ord-e {
margin-right: -4px;
right: 0;
}
.jcrop-dragbar.ord-w {
margin-left: -4px;
}
/* The "jcrop-light" class/extension */
.jcrop-light .jcrop-vline,
.jcrop-light .jcrop-hline {
background: #ffffff;
filter: alpha(opacity=70) !important;
opacity: .70!important;
}
.jcrop-light .jcrop-handle {
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
background-color: #000000;
border-color: #ffffff;
border-radius: 3px;
}
/* The "jcrop-dark" class/extension */
.jcrop-dark .jcrop-vline,
.jcrop-dark .jcrop-hline {
background: #000000;
filter: alpha(opacity=70) !important;
opacity: 0.7 !important;
}
.jcrop-dark .jcrop-handle {
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
background-color: #ffffff;
border-color: #000000;
border-radius: 3px;
}
/* Simple macro to turn off the antlines */
.solid-line .jcrop-vline,
.solid-line .jcrop-hline {
background: #ffffff;
}
/* Fix for twitter bootstrap et al. */
.jcrop-holder img,
img.jcrop-preview {
max-width: none;
}
13 changes: 11 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE HTML>
<!--
/*
* JavaScript Load Image Demo 1.8.0
* JavaScript Load Image Demo 1.9.0
* https://github.com/blueimp/JavaScript-Load-Image
*
* Copyright 2011, Sebastian Tschan
Expand All @@ -20,6 +20,8 @@
<title>JavaScript Load Image</title>
<meta name="description" content="JavaScript Load Image is a library to load images provided as File or Blob objects or via URL. It returns an optionally scaled and/or cropped HTML img or canvas element. It also provides a method to parse image meta data to extract Exif tags and thumbnails and to restore the complete image header after resizing.">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Jcrop is not required by JavaScript Load Image, but included for the demo -->
<link rel="stylesheet" href="css/vendor/jquery.Jcrop.css">
<link rel="stylesheet" href="css/demo.css">
</head>
<body>
Expand All @@ -34,11 +36,16 @@ <h1>JavaScript Load Image Demo</h1>
<li><a href="test/">Test</a></li>
<li><a href="https://blueimp.net">&copy; Sebastian Tschan</a></li>
</ul>
<br>
<h2>Select an image file</h2>
<p><input type="file" id="file-input"></p>
<p>Or <strong>drag &amp; drop</strong> an image file onto this webpage.</p>
<br>
<h2>Result</h2>
<p id="actions" style="display:none;">
<button type="button" id="edit">Edit</button>
<button type="button" id="crop">Crop</button>
</p>
<div id="result" class="result">
<p>This demo works only in browsers with support for the <a href="https://developer.mozilla.org/en/DOM/window.URL">URL</a> or <a href="https://developer.mozilla.org/en/DOM/FileReader">FileReader</a> API.</p>
</div>
Expand All @@ -51,11 +58,13 @@ <h2>Exif meta data</h2>
<br>
<script src="js/load-image.js"></script>
<script src="js/load-image-ios.js"></script>
<script src="js/load-image-orientation.js"></script>
<script src="js/load-image-meta.js"></script>
<script src="js/load-image-exif.js"></script>
<script src="js/load-image-exif-map.js"></script>
<!-- jQuery is not required by JavaScript Load Image, but included for the demo -->
<!-- jQuery and Jcrop are not required by JavaScript Load Image, but included for the demo -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="js/vendor/jquery.Jcrop.js"></script>
<script src="js/demo.js"></script>
</body>
</html>
Loading

0 comments on commit c1b88ae

Please sign in to comment.