var canvas = document.getElementById("myCanvas"),
context = canvas.getContext("2d");
var img = new Image();
var imgT = new Image();
var loaded = 0;
img.src = "https://img.rosbalt.ru/photobank/1/c/a/0/Z8X2VMCx.jpg";
imgT.src = "http://zabavnik.club/wp-content/uploads/background_html_1_16082041.jpg"
imgT.onload = img.onload = function() {
if(++loaded == 2)
draw();
};
function draw(){
context.drawImage(imgT, 300, 400,200,200);
context.drawImage(img, 0, 0);
console.log(canvas.toDataURL());
}
class Draw {
constructor(h, w, id) {
this.h = h;
this.w = w;
}
create(elem) {
let createConvas = document.querySelector('div');
createConvas.innerHTML = `<canvas width=${this.w} height=${this.h}></canvas>`;
this.ctx = createConvas.querySelector("canvas").getContext("2d");
return createConvas;
}
}
class Rect extends Draw {
constructor(elem, x, y, w, h) {
super(elem, x, w, h);
this.y = y;
}
create(elem) {
super.create(elem);
this.ctx.fillRect(20, 20, 150, 100);
}
}
let rect = new Rect(300, 300, '24');
rect.create();
$("li").on("click", function() {
var $myLi = $(this);
var listHeight = $("ul").innerHeight();
var elemHeight = $myLi.height();
var elemTop = $myLi.position().top;
var moveDown = elemHeight;
var moveUp = (listHeight - elemTop - moveDown);
var liId = $myLi.attr("id");
var enough = false;
var liHtml = $myLi.outerHTML();
$($("li").get().reverse()).each(function() {
if ($(this).attr("id") == liId) {
return false;
}
$(this).animate({"top": '-=' + moveDown}, 1000);
});
$myLi.animate({"top": '+=' + moveUp}, 1000, function() {
$myLi.remove();
var oldHtml = $("ul").html();
$("ul").html(oldHtml + liHtml );
$("li").attr("style", "");
});
});
(function($) {
$.fn.outerHTML = function() {
return $(this).clone().wrap('<div></div>').parent().html();
}
})(jQuery);
$('.one').click(function(){
$btn = $('<button type="button" class="two">Увеличить</button>');
$('.forInput').append($btn);
$btn.click(clickHandler);
$('.forInput').append('<input type="text" class="inputone" data-price="1000">');
});
function clickHandler(){
let new_price = parseInt($(this).next().attr('data-price')) + 100;
$(this).next().attr('data-price', new_price);
$(this).next().val(new_price);
}
',' тут now.getMonth()
var now = new Date();
var today = '['+now.getFullYear()+','+now.getMonth()+','+now.getDate()+']';
alert(today);
namespace iconGen
{
public partial class Form1 : Form
{
public Form1(){
InitializeComponent();
var exts = new List<string>(){
".jpg",".png",".gif",".jpeg",".bmp"
};
foreach (var ext in exts)
{
cbl_exts.Items.Add(ext);
cbl_exts.SetItemChecked(cbl_exts.Items.Count-1,true);
}
tb_savepath.Text = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
}
public Dictionary<String, Bitmap> scanDir(string path, List<String> extsVal)
{
Dictionary<String, Bitmap> result = new Dictionary<string, Bitmap>();
var dirs = Directory.GetDirectories(path);
foreach (var dir in dirs){
if (Directory.GetFiles(dir).Where(s => extsVal.Contains(new FileInfo(s).Extension)).Count() > 0)
{
string name = new FileInfo(dir).Name;
string newname = name;
for (var i = 1; result.ContainsKey(newname); i++)
newname = name + "_" + i;
result.Add(newname, createImg(dir, Int32.Parse(tb_width.Text), Int32.Parse(tb_height.Text), Int32.Parse(tb_wh.Text),
cb_auto.Checked, Int32.Parse(tb_padding.Text), extsVal));
}
var res = scanDir(dir, extsVal);
foreach (var key in res.Keys){
string newname = key;
for (var i = 1; result.ContainsKey(newname); i++)
newname = key+ "_" + i;
Bitmap bm;
res.TryGetValue(key, out bm);
result.Add(newname, bm);
bm.Dispose();
}
}
return result;
}
public Bitmap createImg(string path,int imgWidth,int imgHeight,int iconWH,bool isAutoWH,int padding,List<string> exts){
var files = Directory.GetFiles(path).Where(s => exts.Contains(new FileInfo(s).Extension)).ToArray();
var count = files.Length;
if (isAutoWH)
{
for (int i = Math.Min(imgWidth, imgHeight); i > 0; i--)
{
var maxCount = Math.Floor((double)imgWidth / i) * Math.Floor((double)imgHeight / i);
if (maxCount >= count)
{
iconWH = i - padding <= 0 ? i : i - padding;
break;
}
}
}
Bitmap bm = new Bitmap(imgWidth, imgHeight);
using (Graphics g = Graphics.FromImage(bm))
{
for (int i = 0; i < count; i++)
{
var img = Image.FromFile(files[i]);
int x = i % (imgWidth / (iconWH + padding)) * (iconWH + padding);
int y = (int)(Math.Floor((double)(i / (imgWidth / (iconWH + padding)))) * (iconWH + padding));
g.DrawImage(img, x, y, iconWH, iconWH);
img.Dispose();
}
}
return bm;
}
private void btn_scandir_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == DialogResult.OK)
tb_scandir.Text = fbd.SelectedPath;
}
private void btn_savepath_Click(object sender, EventArgs e){
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == DialogResult.OK)
tb_savepath.Text = fbd.SelectedPath;
}
private void button1_Click(object sender, EventArgs e){
try
{
List<string> extsVal = new List<string>();
foreach (var checkedItem in cbl_exts.CheckedItems)
extsVal.Add(checkedItem as string);
var t = scanDir(tb_scandir.Text, extsVal);
var p = new DirectoryInfo(tb_savepath.Text);
foreach (var key in t.Keys){
Bitmap bm;
t.TryGetValue(key, out bm);
bm.Save(p.FullName + @"\" + key + ".png", ImageFormat.Png);
bm.Dispose();
}
Process.Start("explorer.exe", p.FullName);
}
catch (Exception ee)
{
MessageBox.Show(ee.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void cb_auto_CheckedChanged(object sender, EventArgs e)
{
tb_wh.ReadOnly = cb_auto.Checked;
}
}
}