Skip to content

Commit

Permalink
docs(example): Add more detail about focalPoint and scale with image …
Browse files Browse the repository at this point in the history
…preview
  • Loading branch information
pitipatdop committed Feb 21, 2017
1 parent b1c3da3 commit 4aa1a3a
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 7 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ all normal `<img />` props can be used
- `cover`: Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus padding).
- `contain`: Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding).
- `stretch`: Scale width and height independently, This may change the aspect ratio of the src.
- `focalPoint`: default=`.5 .5` (work if resizeMode = 'cover')
- `focalPoint`: default=`50% 50%` (work if resizeMode = 'cover')
Decides origin of the where to focus on the image,
- `left`: Keep left most part of the image.
- `right`: Keep right most part of the image.
- `top`: Keep top most part of the image.
- `bottom`: Keep bottom most part of the image.
- `{x} {y}`: (eg. `focalPoint=".75 .5"` or `focalPoint="75% 50%"`) focus on the point `x%` from the left and `y%` from the top.
![img](http://i.imgur.com/XY3jVPX.png)
- `scale`: (work if resizeMode = 'cover') if provided, the image will scale from container width. (Not image original width)
- scale = 1, the image will cover the whole area perfectly

Note: If you do not provide resizeMode, `<BetterImg />` will just render normal `<img />`

Expand All @@ -47,7 +49,7 @@ render() {
src="/img/puppy.jpg"
height={600}
resizeMode="cover"
focalPoint=".75 .5"
focalPoint="75% 50%"
/>
</div>
)
Expand Down
Binary file removed better-img-0.0.0-development.tgz
Binary file not shown.
126 changes: 124 additions & 2 deletions dev/containers/App.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,151 @@


import React, { Component } from 'react';
// import BetterImg from '../../dist';
import BetterImg from '../../src';

export default class App extends Component {

render() {
return (
<div>
<div className="container">
<h1>resizeMode: Contain</h1>
<BetterImg
src="/img/puppy.jpg"
height={600}
resizeMode="contain"
/>
<hr />
<h1>resizeMode: Cover</h1>
<pre>
&lt;BetterImg scale={1} focalPoint="50% 50%"/&gt;
</pre>
<BetterImg
src="/img/puppy.jpg"
height={600}
scale={1}
focalPoint="75% 50%"
resizeMode="cover"
/>
<div className="row">
<div className="col-sm-4">
<pre>
&lt;BetterImg scale={2} focalPoint="0% 0%"/&gt;
</pre>
<BetterImg
src="/img/puppy.jpg"
height={200}
scale={2}
focalPoint="0% 0%"
resizeMode="cover"
/>
</div>
<div className="col-sm-4">
<pre>
&lt;BetterImg scale={2} focalPoint="50% 0%"/&gt;
</pre>
<BetterImg
src="/img/puppy.jpg"
height={200}
scale={2}
focalPoint="50% 0%"
resizeMode="cover"
/>
</div>
<div className="col-sm-4">
<pre>
&lt;BetterImg scale={2} focalPoint="100% 0%"/&gt;
</pre>
<BetterImg
src="/img/puppy.jpg"
height={200}
scale={2}
focalPoint="100% 0%"
resizeMode="cover"
/>
</div>
</div>
<div className="row">
<div className="col-sm-4">
<pre>
&lt;BetterImg scale={2} focalPoint="0% 50%"/&gt;
</pre>
<BetterImg
src="/img/puppy.jpg"
height={200}
scale={2}
focalPoint="0% 50%"
resizeMode="cover"
/>
</div>
<div className="col-sm-4">
<pre>
&lt;BetterImg scale={2} focalPoint="50% 50%"/&gt;
</pre>
<BetterImg
src="/img/puppy.jpg"
height={200}
scale={2}
focalPoint="50% 50%"
resizeMode="cover"
/>
</div>
<div className="col-sm-4">
<pre>
&lt;BetterImg scale={2} focalPoint="100% 50%"/&gt;
</pre>
<BetterImg
src="/img/puppy.jpg"
height={200}
scale={2}
focalPoint="100% 50%"
resizeMode="cover"
/>
</div>
</div>
<div className="row">
<div className="col-sm-4">
<pre>
&lt;BetterImg scale={2} focalPoint="0% 100%"/&gt;
</pre>
<BetterImg
src="/img/puppy.jpg"
height={200}
scale={2}
focalPoint="0% 100%"
resizeMode="cover"
/>
</div>
<div className="col-sm-4">
<pre>
&lt;BetterImg scale={2} focalPoint="0% 50%"/&gt;
</pre>
<BetterImg
src="/img/puppy.jpg"
height={200}
scale={2}
focalPoint="50% 100%"
resizeMode="cover"
/>
</div>
<div className="col-sm-4">
<pre>
&lt;BetterImg scale={2} focalPoint="0% 100%"/&gt;
</pre>
<BetterImg
src="/img/puppy.jpg"
height={200}
scale={2}
focalPoint="100% 100%"
resizeMode="cover"
/>
</div>
</div>
<hr />
<h1>resizeMode: Stretch</h1>
<BetterImg
src="/img/puppy.jpg"
height={600}
height={400}
resizeMode="stretch"
/>
</div>
Expand Down
File renamed without changes
17 changes: 17 additions & 0 deletions index.html → dev/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@
<meta http-equiv='Expires' content='-1'>
<meta http-equiv='Pragma' content='no-cache'>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" />
<style type="text/css">
pre {
display: block;
padding: 9.5px;
margin: 30px 0 0px;
font-size: 13px;
line-height: 1.42;
color: #333;
background:#f5f5f5;
border: 1px solid #ccc;
border-radius: 4px;
}
.better-img {
border: 1px solid black;
}
</style>
<title>BetterImg Demo</title>
</head>
<body>
Expand Down
6 changes: 4 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ var config = require('./webpack.config.dev');
var app = express();
var compiler = webpack(config);

var DEV_FOLDER = 'dev';

app.use(require('webpack-dev-middleware')(compiler, {
// noInfo: true,
publicPath: config.output.publicPath,
Expand All @@ -28,9 +30,9 @@ app.use(require('webpack-dev-middleware')(compiler, {

app.use(require('webpack-hot-middleware')(compiler));

app.use('/img', express.static('img'));
app.use('/img', express.static(DEV_FOLDER + '/img'));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'index.html'));
res.sendFile(path.join(__dirname, DEV_FOLDER + '/index.html'));
});

app.listen(3000, (err) => {
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ class BetterImg extends Component {

const wrapperStyles = {
overflow: 'hidden',
position: 'relative',
// If props.width is provide, use it, else no need to control container's width
width: this.props.width ? this.props.width : undefined,
height: containerHeight,
border: '1px solid black',
};

// Calculate Scale
Expand Down

0 comments on commit 4aa1a3a

Please sign in to comment.