{"id":13602479,"url":"https://github.com/jasscia/ChristmasHat","last_synced_at":"2025-04-11T08:32:51.501Z","repository":{"id":74492800,"uuid":"116223152","full_name":"jasscia/ChristmasHat","owner":"jasscia","description":"我要圣诞帽 微信小程序","archived":false,"fork":false,"pushed_at":"2018-05-04T06:42:14.000Z","size":1727,"stargazers_count":288,"open_issues_count":5,"forks_count":78,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-11-07T05:39:29.192Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jasscia.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-01-04T06:26:00.000Z","updated_at":"2024-10-28T03:21:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"1f8fe88a-2dd0-46cd-bc9a-f9bc74ba0e91","html_url":"https://github.com/jasscia/ChristmasHat","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasscia%2FChristmasHat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasscia%2FChristmasHat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasscia%2FChristmasHat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasscia%2FChristmasHat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jasscia","download_url":"https://codeload.github.com/jasscia/ChristmasHat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248361664,"owners_count":21090959,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T18:01:24.759Z","updated_at":"2025-04-11T08:32:46.479Z","avatar_url":"https://github.com/jasscia.png","language":"JavaScript","funding_links":[],"categories":["Demo","JavaScript"],"sub_categories":["数据接口有问题"],"readme":"# 我要圣诞帽\n采用微信小程序编写       实现了为图片带帽子的功能\u003cbr\u003e\n## 程序结构如下\n* image (在此放置所有圣诞帽的素材)\n* pages (包含了index imageeditor combine文件夹，每个文件夹中都有四个文件，后缀名分别为 .js .json .wxss .wxml)\n  * index (第一步：选择底图，程序设计三个底图来源 即微信头像、相机、相册)\n  * imageeditor(第二步：实现选择圣诞帽  并通过移动和旋转调整圣诞帽的大小和位置)\n  * combine(第三步：将底图和调整后的圣诞帽合成新的图片 并保存至微信相册)\n* app.js\n* app.json\n* app.wxss\n* project.config.json\n## 过程展示\n##### step 1  旋转底图\n![step1](https://github.com/jasscia/ChristmasHat/raw/master/shortcut/step1.jpg)\n##### step 2 确定底图后 进入下一步\n![step2](https://github.com/jasscia/ChristmasHat/raw/master/shortcut/step2.jpg)\n##### step 3 选择帽子 调整帽子 确定进入下一步\n![step3](https://github.com/jasscia/ChristmasHat/raw/master/shortcut/step3.jpg)\n##### step 4 canvas绘制合成图 并保存至相册\n![step4](https://github.com/jasscia/ChristmasHat/raw/master/shortcut/step4.jpg)\n##### 最终成果 \n![成果图](https://github.com/jasscia/ChristmasHat/raw/master/shortcut/avatarWithHat.png)\n## 核心算法介绍\n* 核心算法1:怎么实现 帽子的实时转动\n   * 当touchstart时，保存此时的touch起始点，并以此时的底图和帽子位置作为旋转角度和缩放比例值计算的参考点\n   * 当touchmove时，根据起始点 和 临时的终止点 计算在x/y方向上的移动距离，计算参考点分别 加上这个距离，得到移动后的位置，通过移动前后的位置 计算移动前后位置的变动 计算旋转角和缩放比例\n   * 当touchend时，重置底图和帽子的位置及旋转角和缩放比例\n* 核心算法2:怎么实现 合成图片(利用canvas)\n    * 首先绘制底图（根据屏幕大小、图片大小计算左上角和右下角坐标）\n    * 绘制帽子（计算最终帽子的大小及中心位置 旋转角度,移动画布原点到帽子的中心位置，旋转画布 并绘制帽子）\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjasscia%2FChristmasHat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjasscia%2FChristmasHat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjasscia%2FChristmasHat/lists"}