<div class="work_area"> <img src="/resources/images/angelina.jpg" width="500" height="600" id="main_img_big" /> </div> <div class="applications_div"> <img src="/resources/applications/1.png" width="64" height="64" /> <img src="/resources/applications/2.png" width="64" height="64" /> <img src="/resources/applications/3.png" width="64" height="64" /> <img src="/resources/applications/4.png" width="64" height="64" /> <img src="/resources/applications/5.png" width="64" height="64" /> <img src="/resources/applications/6.png" width="64" height="64" /> <img src="/resources/applications/7.png" width="64" height="64" /> </div>
var num_elem = 0; // function addApplication(element){ var applicImg = element.clone(); // // applicImg.removeAttr('width'); applicImg.removeAttr('height'); // var allElement = '<div class="applic_new_el_div" id="move_applic_'+num_elem+'"><span class="close_applic"></span></div>'; $('.work_area').append(allElement); // applicImg.addClass('applic_new_el'); // $('#move_applic_'+num_elem).css({ 'top': '0px', 'left': '0px' }); applicImg.attr('id', 'applic_'+num_elem); // $('#move_applic_'+num_elem).append(applicImg); init_drag(num_elem); // init_resize(num_elem); // num_elem ++; // }
// function init_resize(num_el){ $('#move_applic_'+num_el).resizable({ aspectRatio: true, // handles: 'ne, nw, se, sw', // alsoResize: "#applic_"+num_el // - }); }
// function init_drag(num_el){ $('#move_applic_'+num_el).draggable({ cursor: 'move', // containment: '.work_area', // scroll: false, // drag: null // }); }
// . function ajaxMakeImage(){ // var arrayWidth = []; var arrayHeight = []; var arraySrc = []; var arrayTop = []; var arrayLeft = []; var srcImage = $('#main_img_big').attr('src'); var workAreaTop = $('.work_area').offset().top; var workAreaLeft = $('.work_area').offset().left; var num = 0; $('.applic_new_el_div').each(function(e) { arrayWidth[num] = $(this).width(); arrayHeight[num] = $(this).height(); arraySrc[num] = $(this).children('.applic_new_el').attr('src'); arrayTop[num] = $(this).offset().top; arrayLeft[num] = $(this).offset().left; num++; }); // $.ajax({ type: "POST", url: "/ajax_action.php", data: { 'arraySrc': arraySrc, // 'arrayWidth': arrayWidth, // 'arrayHeight': arrayHeight,// 'arrayTop': arrayTop, // 'arrayLeft': arrayLeft, // 'srcImage': srcImage, // ( ) 'workAreaTop': workAreaTop, // 'workAreaLeft': workAreaLeft, // }, dataType: "json", success: function(data){ if(data.result == 'success'){ // // $('#test_show').attr('src', data.imgSrc); alert(' '); }else{ // error // @todo } } }); }
function resizePhotoPNG($source, $path, $height, $width){ $rgb = 0xffffff; // $size = getimagesize($source);// $xRatio = $width / $size[0]; // $yRatio = $height / $size[1]; // $ratio = min($xRatio, $yRatio); $kRatio = ($xRatio == $ratio); // $new_width = $kRatio ? $width : floor($size[0] * $ratio); // $new_height = !$kRatio ? $height : floor($size[1] * $ratio); // // $new_left = $kRatio ? 0 : floor(($width - $new_width) / 2); // $newTop = !$kRatio ? 0 : floor(($height - $new_height) / 2); // $img = imagecreatetruecolor($width, $height); imagealphablending($img, false); imagesavealpha($img, true); $photo = imagecreatefrompng($source); // imagecopyresampled($img, $photo, $new_left, $newTop, 0, 0, $new_width, $new_height, $size[0], $size[1]); // imagepng($img, $path); // // imagedestroy($img); imagedestroy($photo); // return $path; }
// $arrayApplication – // $mainImg – foreach($arrayApplication as $k=>$oneAppl){ // $imageFon = imagecreatefrompng($oneAppl); imagealphablending($imageFon, false); imagesavealpha($imageFon, true); // imagecopy($mainImg, $imageFon, $applX[$k]-$imgX, $applY[$k]-$imgY, 0, 0, imagesx($imageFon), imagesy($imageFon)); }
imageJpeg($mainImg, $pathForImg, 100); // $pathForImg 100 // imagedestroy($mainImg);
$result = array( 'result' => 'success', // 'imgSrc' => $resultSrc // ); echo json_encode($result); // JSON
Source: https://habr.com/ru/post/211260/
All Articles