Just realize that croppie implementation maybe not standard... :
The complete code for the blade referring to cropimage.js:
@extends('layout')
@section('header')
@include('includes.basic_header')
@stop
@section('content')
<div class="container center account-container">
<div>
@if (!$valid)
<p><b>{{ __('Welcome at Detective Collective!') }}</b><p>
<p>{{ __('Before you begin with solving crimes, you first need to finish your profile.') }}</p>
@endif
<h5 class="header_dark">{{ __('My Profile') }}</h5>
<form method='POST' id="account_form" runat="server" action="profile/submit" enctype="multipart/form-data">
{{ csrf_field() }}
@foreach ($errors->all() as $error)
<h6 class="red">{{ $error }}</h6>
@endforeach
<p><b>{{ __('Profile photo') }}</b></p>
<input type='file' id="file_picture_input"/>
<br>
<img id="picture_preview" src="{{ url('') }}/images/profile" alt="" style="width:180px; box-shadow: 0px 0px 15px #444;"/>
<div id="picture_preview_container"></div>
<div id="rotateleft" class="btn" style="display: none;">{{ __('Rotate left') }}</div>
<div id="rotateright" class="btn" style="display: none;">{{ __('Rotate right') }}</div>
<input type="hidden" id="picture_input" name="picture_input"/>
<p>{!! __('<b>Be aware!</b> Your profile photo needs to be a clear photo of your face, so other players can easily recognize you.') !!}</p>
<p><b>{{ __('First name') }}</b></p>
<input type='hidden' placeholder="{{ __('First name') }}" name="first_name" value="{{ $profile->first_name }}"/>
<p><b>{{ __('Last name') }}</b></p>
<input type='text' placeholder="{{ __('Last name') }}" name="last_name" value="{{ $profile->last_name }}"/>
<p><b>{{ __('Email address') }}</b></p>
<p>{{ __('Your e-mail address will only be used for this game.') }}</p>
<input type='email' placeholder="{{ __('Email address') }}" name="email" value="{{ $email }}"/>
@if($game_user_availability->active())
<div class="row">
<div class="col s12">
<div class="card blue-grey darken-1 card-all-white-text">
<div class="card-content white-text">
<span class="card-title">{{ $availability_main_label }}</span>
<div class="row">
<p>{{ $availability_question_days }}</p>
</div>
<div class="row">
@if($allowed_days['mon'])
<div class="col s4">
<input type="checkbox" id="gameuser_availability_mon" value="1" name="gameuser_availability_mon" {{ old('gameuser_availability_mon',$game_user_availability->mon) ? 'checked' : '' }}/>
<label for="gameuser_availability_mon">{{ __('Mon') }}</label>
</div>
@endif
@if($allowed_days['tue'])
<div class="col s4">
<input type="checkbox" id="gameuser_availability_tue" value="1" name="gameuser_availability_tue" {{ old('gameuser_availability_tue',$game_user_availability->tue) ? 'checked' : '' }}/>
<label for="gameuser_availability_tue">{{ __('Tue') }}</label>
</div>
@endif
@if($allowed_days['wed'])
<div class="col s4">
<input type="checkbox" id="gameuser_availability_wed" value="1" name="gameuser_availability_wed" {{ old('gameuser_availability_wed',$game_user_availability->wed) ? 'checked' : '' }}/>
<label for="gameuser_availability_wed">{{ __('Wed') }}</label>
</div>
@endif
@if($allowed_days['thu'])
<div class="col s4">
<input type="checkbox" id="gameuser_availability_thu" value="1" name="gameuser_availability_thu" {{ old('gameuser_availability_thu',$game_user_availability->thu) ? 'checked' : '' }}/>
<label for="gameuser_availability_thu">{{ __('Thu') }}</label>
</div>
@endif
@if($allowed_days['fri'])
<div class="col s4">
<input type="checkbox" id="gameuser_availability_fri" value="1" name="gameuser_availability_fri" {{ old('gameuser_availability_fri',$game_user_availability->fri) ? 'checked' : '' }}/>
<label for="gameuser_availability_fri">{{ __('Fri') }}</label>
</div>
@endif
@if($allowed_days['sat'])
<div class="col s4">
<input type="checkbox" id="gameuser_availability_sat" value="1" name="gameuser_availability_sat" {{ old('gameuser_availability_sat',$game_user_availability->sat) ? 'checked' : '' }}/>
<label for="gameuser_availability_sat">{{ __('Sat') }}</label>
</div>
@endif
@if($allowed_days['sun'])
<div class="col s4">
<input type="checkbox" id="gameuser_availability_sun" value="1" name="gameuser_availability_sun" {{ old('gameuser_availability_sun',$game_user_availability->sun) ? 'checked' : '' }}/>
<label for="gameuser_availability_sun">{{ __('Sun') }}</label>
</div>
@endif
</div>
<div class="row">
<p>{{ $availability_question_location }}</p>
</div>
<div class="row">
<div class="input-field col s12">
<select name="location_id">
<option value="" disabled selected>{{ __('Select an option') }}</option>
@foreach($locations as $location)
<option value="{{ $location->id }}" {{ old('location_id', $game_user_availability->location_id) == $location->id ? 'selected="selected"' : ''}}>{{ $location->label }}</option>
@endforeach
</select>
</div>
</div>
<div class="row">
<p>{{ $availability_question_floor_level }}</p>
@for ($i = 0; $i < 9; $i++)
<div class="col s4">
<input name="floor_level[]" type="checkbox" value="{{ $i + 1 }}" id="floor_level_{{ $i }}" {{ in_array(($i + 1), old('floor_level', $game_user_availability->getAllFloors())) ? 'checked="checked"' : '' }}/>
<label for="floor_level_{{ $i }}">{{ $i + 1 }}</label>
</div>
@endfor
</div>
</div>
</div>
</div>
@endif
<input class="btn-large" type="submit" id="submit_button" value="{{ __('Finish') }}">
</form>
</div>
</div>
<script src="{{ url('js/cropimage.js') }}"></script>
@stop
and the complete js/cropimage.js that generates the error:
var uploadCroppie;
var globalFileURL;
$(function() { //shorthand document.ready function
$('#submit_button').on('click', function(e) { //use on if jQuery 1.7+
e.preventDefault(); //prevent form from submitting
if(uploadCroppie){
uploadCroppie.croppie('result', {
type: 'base64',
size: {
width: 250,
height: 250
} //'viewport'
}).then(function (resp) {
$('#picture_input').val(resp);
$('#account_form').submit();
});
}else{
$('#account_form').submit();
}
});
$('#rotateleft').click(function(){
if(uploadCroppie){
// $(uploadCroppie).croppie('bind', {
// url: globalFileURL
// });
$(uploadCroppie).croppie('rotate', -90);
// if (deg === 90 || deg === -270) ornt = 6;
// if (deg === -90 || deg === 270) ornt = 8;
// if (deg === 180 || deg === -180) ornt = 3;
}
});
$('#rotateright').click(function(){
if(uploadCroppie){
$(uploadCroppie).croppie('rotate', 90);
}
});
});
//test if input is a valid image
if (window.File && window.FileReader && window.FormData) {
// var $inputField = $('input[name="picture_input"]');
var $inputField = $('#file_picture_input');
$inputField.on('change', function (e) {
var file = e.target.files[0];
if (file) {
if (/^image\//i.test(file.type)) {
readFile(file);
} else {
alert('Not a valid image!');
}
}
});
} else {
alert("File upload is not supported!");
}
function readFile(file) {
var reader = new FileReader();
reader.onloadend = function () {
processFile(reader.result, file.type);
}
reader.onerror = function () {
alert('There was an error reading the file!');
}
reader.readAsDataURL(file);
}
//resize the image
function processFile(dataURL, fileType) {
var maxWidth = 576;
var maxHeight = 576;
var image = new Image();
image.src = dataURL;
image.onload = function () {
var width = image.width;
var height = image.height;
var shouldResize = (width > maxWidth) && (height > maxHeight);
// if (!shouldResize) {
// $('#picture_preview').attr('src', dataURL);
// return;
// }
// var newWidth;
// var newHeight;
// if (width < height) {
// newHeight = height * (maxWidth / width);
// newWidth = maxWidth;
// } else {
// newWidth = width * (maxHeight / height);
// newHeight = maxHeight;
// }
// var canvas = document.createElement('canvas');
// canvas.width = newWidth;
// canvas.height = newHeight;
// var context = canvas.getContext('2d');
// context.drawImage(this, 0, 0, newWidth, newHeight);
// dataURL = canvas.toDataURL(fileType);
//$('#picture_preview').attr('src', dataURL);
$('#picture_preview').hide();
$('#picture_preview_container').height(300);
globalFileURL = dataURL;
if(uploadCroppie){
$(uploadCroppie).croppie('destroy');
}
uploadCroppie = $('#picture_preview_container').croppie({
//url: dataURL,
viewport: {
width: 250,
height: 250
},
// enableExif: true,
enableOrientation: true,
enableZoom: false,
// update: function (data) {
// var result = this.result({
// type: 'base64',
// });
// },
// result: function (data) {
// console.log(data);
// },
});
$(uploadCroppie).croppie('bind', {
url: globalFileURL
});
$('#rotateleft').show();
$('#rotateright').show();
//$('#picture_input').attr('value', dataURL);
};
image.onerror = function () {
alert('There was an error processing your file!');
};
}