Skip to content
This repository has been archived by the owner on Nov 24, 2021. It is now read-only.

schema option to presave image dimensions #28

Open
eliataylor opened this issue Nov 7, 2017 · 1 comment
Open

schema option to presave image dimensions #28

eliataylor opened this issue Nov 7, 2017 · 1 comment

Comments

@eliataylor
Copy link

more of an Enhancement request, but might there be plans to allow saving image dimensions in the schema?

schema { dimensions:true,...

@eliataylor
Copy link
Author

eliataylor commented Nov 13, 2017

found this is easily done by adding the fields to the schema:

@ https://github.com/keystonejs/keystone-storage-adapter-s3/blob/master/index.js#L65

S3Adapter.SCHEMA_FIELD_DEFAULTS = {
	filename: true,
	bucket: false,
	path: false,
	etag: false,
	width:false,
	height:false,
	wUnits:false,
	hUnits:false
};

then I added a post save method:

then I implemented the updates with:

const Probe = require('probe-image-size');
Content.schema.post('save',(doc,next)=>{
	
	if (doc.image && doc.image.url) {
		Probe(doc.image.url, function (err, result) {
			if (err) console.log(err);
		  console.log(doc.image, result);
			doc.image.width = result.width;
			doc.image.height = result.height;
			doc.image.wUnits = result.wUnits;
			doc.image.hUnits = result.hUnits;
			console.log('UPDATING IMAGE', doc.image);
			return keystone.list('Content').model.update({'_id': doc._id}, {image: doc.image}).exec();
		});
	}
});

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant