Explorar o código

截取固定比例图

huangct %!s(int64=8) %!d(string=hai) anos
pai
achega
6592d385aa

+ 1 - 0
jpress-web-admin/src/main/java/io/jpress/admin/controller/_AttachmentController.java

@@ -98,6 +98,7 @@ public class _AttachmentController extends JBaseCRUDController<Attachment> {
 		Page<Attachment> page = AttachmentQuery.me().paginate(getPageNumber(), getPageSize(), null, null, null, null,
 				getPara("k", "").trim(), getPara("dm"), getPara("mime"), null);
 		setAttr("page", page);
+		setAttr("imageSize", getPara("size"));
 		render("choose_layer.html");
 	}
 

+ 24 - 11
jpress-web-admin/src/main/webapp/WEB-INF/admin/attachment/choose_layer.html

@@ -26,16 +26,27 @@ $(document).ready(function(){
     $(this).next().show();
   });
 
-    $('.jp-grids-photos').imgAreaSelect({ maxWidth: 200, maxHeight: 170, handles: true });
-
-    $('.jp-grids-photos').imgAreaSelect({
-        onSelectEnd: function (img, selection) {
-            $('input[name="x1"]').val(selection.x1);
-            $('input[name="y1"]').val(selection.y1);
-            $('input[name="x2"]').val(selection.x2);
-            $('input[name="y2"]').val(selection.y2);
-        }
-    });
+    <#if imageSize?? && imageSize=="bigImage">
+        $('.jp-grids-photos').imgAreaSelect({aspectRatio: '470:300', maxWidth: 94, maxHeight: 60, handles: true });
+        $('.jp-grids-photos').imgAreaSelect({
+            onSelectEnd: function (img, selection) {
+                $('input[name="x1"]').val(selection.x1);
+                $('input[name="y1"]').val(selection.y1);
+                $('input[name="x2"]').val(selection.x2);
+                $('input[name="y2"]').val(selection.y2);
+            }
+        });
+    <#elseif imageSize?? && imageSize=="smallImage">
+        $('.jp-grids-photos').imgAreaSelect({aspectRatio: '1:1', maxWidth: 50, maxHeight: 50, handles: true });
+        $('.jp-grids-photos').imgAreaSelect({
+            onSelectEnd: function (img, selection) {
+                $('input[name="x1"]').val(selection.x1);
+                $('input[name="y1"]').val(selection.y1);
+                $('input[name="x2"]').val(selection.x2);
+                $('input[name="y2"]').val(selection.y2);
+            }
+        });
+    </#if>
 });
 
 $('#fine-uploader-gallery').fineUploader({
@@ -134,7 +145,9 @@ function doUpload(sourceId) {
 									<div class="brower-active-icon" style="display: none">
 										<i class="fa fa-check-square-o fa-2x" aria-hidden="true"></i>
 									</div>
-                                    <button onclick="doUpload(${bean.id})">确定</button>
+                                    <#if imageSize?? && imageSize != "undefined">
+                                        <button onclick="doUpload(${bean.id})">确定</button>
+                                    </#if>
 								</li>
 								</#list>
 								</#if>

+ 2 - 2
jpress-web-admin/src/main/webapp/WEB-INF/admin/content/_edit_include.html

@@ -390,10 +390,10 @@
 								<p>封面</p>
 								<!--大图-->
 								<input type="hidden" name="content.thumbnail" value="${(content.thumbnail)!}" id="content_thumbnail">
-								<span class="inputUas" onclick="doSelectThumbnail()" onchange="Javascript:validImg(this);"><em>从图库选择</em><!--<input type="file">--></span>
+								<span class="inputUas" onclick="doSelectThumbnail('bigImage')" onchange="Javascript:validImg(this);"><em>从图库选择</em><!--<input type="file">--></span>
 								<!--小图-->
 								<input type="hidden" name="content.thumbnail" value="${(content.thumbnail)!}" id="content_thumbnail">
-								<span class="inputUas" onclick="doSelectThumbnail()" onchange="Javascript:validImg(this);"><em>从图库选择</em><!--<input type="file">--></span>
+								<span class="inputUas" onclick="doSelectThumbnail('smallImage')" onchange="Javascript:validImg(this);"><em>从图库选择</em><!--<input type="file">--></span>
 							</div>
 							<!--大图-->
 							<div class="showImg">

+ 2 - 2
jpress-web-admin/src/main/webapp/WEB-INF/admin/content/edit.html

@@ -156,14 +156,14 @@ function turnPage(){
 	});
  }
  
-function doSelectThumbnail(){
+function doSelectThumbnail(size){
  	layer.open({
 			    type: 2,
 			    title: '选择图片',
 			    shadeClose: true,
 			    shade: 0.8,
 			    area: ['92%', '90%'],
-			    content: '${CPATH}/admin/attachment/choose_layer',
+			    content: '${CPATH}/admin/attachment/choose_layer?size=' + size,
 			    end:function(){
 			    	if(''!=data.url && null != data.url){
 			    		$("#thumbnail").attr("src",data.url);