124 lines
5.8 KiB
HTML
124 lines
5.8 KiB
HTML
{% extends "base.html" %} {% block main_content %}
|
|
<script>
|
|
// Define this once and before it will be called, hence at the top of this file
|
|
function DrawRefimg(fig, img, canvas, orig_face )
|
|
{
|
|
// FIXME: should get this from shared.py, not sure why this doesnt work at present
|
|
thumbsize=256
|
|
|
|
context=canvas.getContext('2d')
|
|
// another call to this func will occur on load, so skip this one
|
|
if( img.width == 0 )
|
|
return
|
|
|
|
// only set canvas.width once we have valid img dimensions
|
|
canvas.width=img.width/2
|
|
|
|
// actually draw the pixel images to the canvas at the right size
|
|
context.drawImage(img, 0, 0, img.width/(img.height/canvas.height), canvas.height);
|
|
fig.width(canvas.width)
|
|
|
|
// draw rectangle on face
|
|
context.beginPath();
|
|
new_x=(orig_face.x/orig_face.orig_w)*img.width/(img.height/canvas.height)
|
|
new_y=(orig_face.y/orig_face.orig_h)*thumbsize/(img.height/canvas.height)
|
|
new_w=(orig_face.w/orig_face.orig_w)*img.width/(img.height/canvas.height)
|
|
new_h=(orig_face.h/orig_face.orig_h)*thumbsize/(img.height/canvas.height)
|
|
context.rect(new_x, new_y, new_w, new_h)
|
|
context.lineWidth = 2;
|
|
context.strokeStyle = 'green';
|
|
context.stroke();
|
|
}
|
|
</script>
|
|
|
|
<div class="container-fluid">
|
|
<div class="row col-12"><h3 class="offset-3">{{page_title}}</h3></div>
|
|
<form id="pfm" class="form form-inline" action="" method="POST">
|
|
{% for field in form %}
|
|
{% if field.type == 'HiddenField' or field.type == 'CSRFTokenField' %}
|
|
{{field}}
|
|
{% elif field.type != 'SubmitField' %}
|
|
<div class="row col-12">
|
|
{{ field.label( class="col-3" ) }}
|
|
{{ field( class="form-control col" ) }}
|
|
</div class="row col-12">
|
|
{% endif %}
|
|
{% endfor %}
|
|
<div class="row col-12">
|
|
<label class="col-3">Reference Images:</label>
|
|
{% for refimg in person.refimg %}
|
|
{% set offset="" %}
|
|
{% if (loop.index % 10) == 0 %}
|
|
{% set offset= "offset-3" %}
|
|
{% endif %}
|
|
<div id="RI{{refimg.id}}" class="col-1 px-0 {{offset}}">
|
|
<input type="hidden" id="ref-img-id-{{refimg.id}}" name="ref-img-id-{{refimg.id}}" value="1"></input>
|
|
<figure id="fig_{{refimg.id}}">
|
|
<div style="position:relative">
|
|
<canvas id="c_{{refimg.id}}" height="128"></canvas>
|
|
<script>
|
|
var im_{{refimg.id}}=new Image();
|
|
im_{{refimg.id}}.src="data:image/jpeg;base64,{{refimg.thumbnail}}";
|
|
fig_{{refimg.id}}=$('#fig_{{refimg.id}}')
|
|
|
|
// store this stuff in an javascript Object to use when document is ready event is triggered
|
|
var orig_face_{{refimg.id}}=new Object;
|
|
orig_face_{{refimg.id}}.x = {{refimg.face_locn[0][3]}}
|
|
orig_face_{{refimg.id}}.y = {{refimg.face_locn[0][0]}}
|
|
orig_face_{{refimg.id}}.w = {{refimg.face_locn[0][1]}}-{{refimg.face_locn[0][3]}}
|
|
orig_face_{{refimg.id}}.h = {{refimg.face_locn[0][2]}}-{{refimg.face_locn[0][0]}}
|
|
orig_face_{{refimg.id}}.orig_w = {{refimg.orig_w}}
|
|
orig_face_{{refimg.id}}.orig_h = {{refimg.orig_h}}
|
|
|
|
// when the document is ready, then DrawRefimg
|
|
$(function() { DrawRefimg( fig_{{refimg.id}}, im_{{refimg.id}}, c_{{refimg.id}}, orig_face_{{refimg.id}} ) });
|
|
|
|
</script>
|
|
<div style="position:absolute; top: 2px; right: 2px;">
|
|
<button type="button" style="font-size:12px" class="btn btn-danger"
|
|
onClick="DelImg({{refimg.id}})">X</button>
|
|
</div>
|
|
<figcaption class="figure-caption text-center text-wrap text-break">{{refimg.fname}}</figcaption>
|
|
</div>
|
|
</figure>
|
|
</div id="/RI*">
|
|
{% endfor %}
|
|
<div id="throb" style="display:none" class="col-1 px-0 {{offset}}">
|
|
<img height="64px" src="{{url_for('static', filename='throbber.gif')}}"></img>
|
|
</div>
|
|
</div class="row col-12">
|
|
<div class="row col-12">
|
|
<br>
|
|
</div class="form-row">
|
|
<div class="row col-12">
|
|
{{ form.save( id="save", class="btn btn-primary offset-3 col-2" )}}
|
|
{% if 'Edit' in page_title %}
|
|
{{ form.delete( class="btn btn-outline-danger col-2" )}}
|
|
{% endif %}
|
|
</div class="form-row">
|
|
</form>
|
|
{% if person.id %}
|
|
<form id="new_ri" class="form" action="{{url_for('add_refimg')}}" method="POST" enctype="multipart/form-data">
|
|
<input type="hidden" name="person_id" value="{{person.id}}"></input>
|
|
<div class="row col-12">
|
|
<label class="btn btn-success offset-3 col-2">
|
|
Add reference image
|
|
<input name="refimg_file" type="file" onChange="$('#throb').attr('style','show'); $('#new_ri').submit()" style="display:none;" id="new_file_chooser">
|
|
</label>
|
|
</div class="row col-12">
|
|
</form>
|
|
{% endif %}
|
|
</div class="container">
|
|
{% endblock main_content %}
|
|
|
|
{% block script_content %}
|
|
<script>
|
|
function DelImg(ri_num)
|
|
{
|
|
$('#RI'+ri_num).remove()
|
|
$('#pfm').submit()
|
|
}
|
|
|
|
</script>
|
|
{% endblock script_content %}
|