Editor Image Upload - how do you store image height/width?
Editor Image Upload - how do you store image height/width?
How do you store the height/width of an uploaded image? I can store the image URL and validate to make sure the image is a certain size but I can't find a way to store the size of a successfully uploaded image.
Field::inst( 'icon' )
->setFormatter( 'Format::nullEmpty' )
->upload(
Upload::inst( function ( $file, $id ) {
move_uploaded_file( $file['tmp_name'], $_SERVER['DOCUMENT_ROOT'].'/groupimg/icons/'.$file['name'] );
return '//snap.fund/groupimg/icons/'.$file['name'];
} )
->validator( function ( $file ) {
return$file['size'] >= 100000 ?
"Files must be smaller than 100K" :
null;
} )
->validator( function ( $file ) {
list($width, $height, $type, $attr) = getimagesize($_SERVER['DOCUMENT_ROOT'].'/groupimg/icons/'.$file['name']);
return$height > 100 ?
"Images should be 100px high" :
null;
} )
->allowedExtensions( [ 'png', 'jpg', 'gif' ], "Please upload an image" )
),
I tried various things using ->db() but none of them worked. Thanks for any help!!!
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi,
I replied to your question about this topic in this thread on Tuesday. As noted there you would need to use a closure function for the
db()
values which would calculate the values required.Regards,
Allan