How can I upload an image in a registration form with image preview and cropping tool using PHP yii framework?
I have a user registration form in my yii framework and want to include an image upload for the user image. I want that the image in uploaded and directly displayed in the form after the upload was successful. After that I want to resize and crop the image and when the create user form is submitted the image should be saved and the user record should contain the url to the image in order to display it later.
How can I set a fixed size for the image to be stored? I.e., when I want to have the image in width 200px x height 300px for example.
For live preview before updating you can use html5
FileAPI.I advice you to look in these links:
file-api-example
https://developer.mozilla.org/en/Using_files_from_web_applications
For cropping images on the server side, please use following yii extension:
http://www.yiiframework.com/extension/image/
You can also let the user crop image on the client side. You can define the fixed aspect ratio and let the select part of the image. I personally use Jcrop javascript library.
You want to have the image to be 200px x 300px. AspectRadio is 0.67 in this case. You define aspectRatio in Jcrop:
Since your aspect ratio is fixed, you only have to resize the image to 200px x 300px using the mentioned extension.