├── .gitignore
├── README.md
├── package-lock.json
├── package.json
├── public
├── favicon.ico
├── index.html
└── manifest.json
├── sample-images
├── meme-gen-img1.png
├── meme-gen-img2.png
└── meme-gen-img3.png
└── src
├── App.jsx
├── components
├── CurrentImage.js
├── Footer.js
├── MemeGenerator.js
├── MemeLibrary.js
└── TextForm.js
├── index.js
├── logo2.svg
├── serviceWorker.js
└── styles
└── index.css
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # React Meme Generator
3 |
4 | A simple react application to make your own memes.
5 |
6 | "_Don't Let your Memes be Dreams._"
7 |
8 | ## Resources
9 |
10 | Images Collected from the [ImgFlip API](https://api.imgflip.com).
11 |
12 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
13 |
14 | ## Sample Images
15 |
16 |
17 |
18 |
19 |
20 | ## To implement later
21 |
22 | - allow option between black | white text
23 | - allow user to select font size
24 | - share on socials
25 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-meme-generator",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "react": "^16.7.0",
7 | "react-dom": "^16.7.0",
8 | "react-scripts": "^2.1.5",
9 | "serve": "^10.1.2"
10 | },
11 | "scripts": {
12 | "start": "react-scripts start",
13 | "build": "react-scripts build",
14 | "test": "react-scripts test",
15 | "eject": "react-scripts eject"
16 | },
17 | "eslintConfig": {
18 | "extends": "react-app"
19 | },
20 | "browserslist": [
21 | ">0.2%",
22 | "not dead",
23 | "not ie <= 11",
24 | "not op_mini all"
25 | ]
26 | }
27 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nulidev/Meme-Generator/b69374b7522bcaf094eeeeca925d9fe784e99fa4/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
22 | React Meme Generator
23 |
24 |
25 | You need to enable JavaScript to run this app.
26 |
27 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | }
10 | ],
11 | "start_url": ".",
12 | "display": "standalone",
13 | "theme_color": "#000000",
14 | "background_color": "#ffffff"
15 | }
16 |
--------------------------------------------------------------------------------
/sample-images/meme-gen-img1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nulidev/Meme-Generator/b69374b7522bcaf094eeeeca925d9fe784e99fa4/sample-images/meme-gen-img1.png
--------------------------------------------------------------------------------
/sample-images/meme-gen-img2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nulidev/Meme-Generator/b69374b7522bcaf094eeeeca925d9fe784e99fa4/sample-images/meme-gen-img2.png
--------------------------------------------------------------------------------
/sample-images/meme-gen-img3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nulidev/Meme-Generator/b69374b7522bcaf094eeeeca925d9fe784e99fa4/sample-images/meme-gen-img3.png
--------------------------------------------------------------------------------
/src/App.jsx:
--------------------------------------------------------------------------------
1 | import React, { Component } from "react";
2 | import logo from "./logo2.svg";
3 | import MemeGenerator from "./components/MemeGenerator";
4 | import Footer from "./components/Footer";
5 |
6 | //this is my main component-as you can see
7 | class App extends Component {
8 | render() {
9 | return (
10 |
11 |
12 |
13 | Meme Generator
14 |
15 |
16 |
17 |
18 | );
19 | }
20 | }
21 |
22 | export default App;
23 |
--------------------------------------------------------------------------------
/src/components/CurrentImage.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | function CurrentImage({ currentImage, addTextToCanvas }) {
4 | const { src, alt } = currentImage;
5 |
6 | return (
7 |
8 | {!src ? (
9 |
10 |
11 | "Click on an image from the{" "}
12 | Meme Library below to load."
13 |
14 |
15 | ) : (
16 |
17 |
18 | Current Image: {alt}
19 |
20 |
21 | Type text on the text box and click on the image to insert the text
22 | in that position.
23 |
24 | Right click on Image and select
25 | "Save image as..."
26 | {" "}
27 | to Save Meme.
28 |
29 |
30 | )}
31 |
32 |
33 |
39 | The Canvas element is not supported in your browser.
40 |
41 |
42 |
43 | );
44 | }
45 |
46 | export default CurrentImage;
47 |
--------------------------------------------------------------------------------
/src/components/Footer.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | function Footer() {
4 | return (
5 |
17 | );
18 | }
19 |
20 | export default Footer;
21 |
--------------------------------------------------------------------------------
/src/components/MemeGenerator.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from "react";
2 | import TextForm from "./TextForm";
3 | import CurrentImage from "./CurrentImage";
4 | import MemeLibrary from "./MemeLibrary";
5 |
6 | class MemeGenerator extends Component {
7 | state = {
8 | userText: "",
9 | allImages: [],
10 | currentImage: "",
11 | allEdits: []
12 | };
13 |
14 | componentDidMount() {
15 | fetch("https://api.imgflip.com/get_memes")
16 | .then(res => res.json())
17 | .then(output => {
18 | this.setState({
19 | allImages: output.data.memes
20 | });
21 | })
22 | .catch(err => console.log(err));
23 | }
24 |
25 | onSaveMeme = e => {
26 | e.preventDefault();
27 |
28 | const canv = document.getElementById("imageCanvas");
29 | // Canvas2Image.saveAsPNG(canv);
30 |
31 | var image = canv
32 | .toDataURL("image/png")
33 | .replace("image/png", "image/octet-stream");
34 | window.location.href = image;
35 | };
36 |
37 | handleTextChange = e => {
38 | const { name, value } = e.target;
39 | this.setState({ [name]: value });
40 | };
41 |
42 | // collected from studyJS: http://www.studyjs.com/canvas/image.html
43 | calculateAspectRatio = function(image) {
44 | let canvas = document.getElementById("imageCanvas");
45 |
46 | let imageAspectRatio = image.width / image.height;
47 | let canvasAspectRatio = canvas.width / canvas.height;
48 | let renderableHeight, renderableWidth, xStart, yStart;
49 | let AspectRatio = {};
50 |
51 | // If image's aspect ratio is less than canvas's we fit on height
52 | // and place the image centrally along width
53 | if (imageAspectRatio < canvasAspectRatio) {
54 | renderableHeight = canvas.height;
55 | renderableWidth = image.width * (renderableHeight / image.height);
56 | xStart = (canvas.width - renderableWidth) / 2;
57 | yStart = 0;
58 | }
59 |
60 | // If image's aspect ratio is greater than canvas's we fit on width
61 | // and place the image centrally along height
62 | else if (imageAspectRatio > canvasAspectRatio) {
63 | renderableWidth = canvas.width;
64 | renderableHeight = image.height * (renderableWidth / image.width);
65 | xStart = 0;
66 | yStart = (canvas.width - renderableHeight) / 2;
67 | }
68 |
69 | //keep aspect ratio
70 | else {
71 | renderableHeight = canvas.height;
72 | renderableWidth = canvas.width;
73 | xStart = 0;
74 | yStart = 0;
75 | }
76 | AspectRatio.renderableHeight = renderableHeight;
77 | AspectRatio.renderableWidth = renderableWidth;
78 | AspectRatio.startX = xStart;
79 | AspectRatio.startY = yStart;
80 | return AspectRatio;
81 | };
82 |
83 | loadImageInCanvas = event => {
84 | const canvas = document.getElementById("imageCanvas");
85 | const ctx = canvas.getContext("2d");
86 |
87 | const img = new Image();
88 | img.src = event ? event.target.src : this.state.currentImage.src;
89 | img.crossOrigin = "Anonymous";
90 | img.addEventListener("load", () => {
91 | ctx.clearRect(0, 0, canvas.width, canvas.height);
92 |
93 | // from studyJS
94 | let AR = this.calculateAspectRatio(img);
95 | ctx.drawImage(
96 | img,
97 | AR.startX,
98 | AR.startY,
99 | AR.renderableWidth,
100 | AR.renderableHeight
101 | );
102 | });
103 | };
104 |
105 | handleImgClick = e => {
106 | this.setState({ currentImage: e.target });
107 |
108 | this.loadImageInCanvas(e);
109 | };
110 |
111 | getMousePos(canvas, e) {
112 | const rect = canvas.getBoundingClientRect();
113 | return {
114 | x: e.clientX - rect.left,
115 | y: e.clientY - rect.top
116 | };
117 | }
118 |
119 | handleText(e) {
120 | const canv = e.target;
121 |
122 | const ctx = canv.getContext("2d");
123 | const pos = this.getMousePos(canv, e);
124 |
125 | ctx.font = "800 40px Impact, Arial";
126 | ctx.fillStyle = "#433487";
127 | ctx.fillText(this.state.userText, pos.x, pos.y);
128 |
129 | this.setState(ps => {
130 | ps.allEdits.push({
131 | posX: pos.x,
132 | posY: pos.y,
133 | text: this.state.userText
134 | });
135 | return ps;
136 | });
137 | }
138 |
139 | addTextToCanvas = e => {
140 | e.preventDefault();
141 | this.handleText(e);
142 | this.setState({ userText: "" });
143 | };
144 |
145 | removeLastText = e => {
146 | e.preventDefault();
147 | const canv = document.getElementById("imageCanvas");
148 | const ctx = canv.getContext("2d");
149 |
150 | this.setState(ps => {
151 | ps.allEdits.pop();
152 | return ps;
153 | });
154 | this.loadImageInCanvas(false);
155 |
156 | setTimeout(() => {
157 | ctx.font = "800 40px Impact, Arial";
158 | ctx.fillStyle = "#433487";
159 | this.state.allEdits.forEach(edit => {
160 | ctx.fillText(edit.text, edit.posX, edit.posY);
161 | });
162 | }, 200);
163 | };
164 |
165 | render() {
166 | return (
167 |
168 | {/* form for text */}
169 |
170 |
176 |
177 | {/* current working image */}
178 |
182 |
183 |
184 |
185 | {/* all meme images */}
186 |
190 |
191 | );
192 | }
193 | }
194 |
195 | export default MemeGenerator;
196 |
--------------------------------------------------------------------------------
/src/components/MemeLibrary.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | function getMemeImageElements(allImages, handleImgClick) {
4 | let imgStyles = {
5 | cursor: "pointer",
6 | width: "150px",
7 | height: "150px"
8 | };
9 |
10 | let memeImages;
11 | if (allImages) {
12 | memeImages = allImages.map(image => (
13 |
14 |
21 |
22 | ));
23 |
24 | return memeImages;
25 | }
26 | return null;
27 | }
28 |
29 | function MemeLibrary(props) {
30 | const { allImages, handleImgClick } = props;
31 |
32 | const memeImages = getMemeImageElements(allImages, handleImgClick);
33 |
34 | return (
35 |
36 |
Meme Library
37 |
{memeImages}
38 |
39 | );
40 | }
41 |
42 | export default MemeLibrary;
43 |
--------------------------------------------------------------------------------
/src/components/TextForm.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | function TextForm(props) {
4 | const { userText, handleTextChange, removeLastText } = props;
5 | return (
6 |
18 | );
19 | }
20 |
21 | export default TextForm;
22 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import ReactDOM from "react-dom";
3 | import App from "./App.jsx";
4 | import * as serviceWorker from "./serviceWorker";
5 | import "./styles/index.css";
6 |
7 | ReactDOM.render( , document.getElementById("root"));
8 |
9 | // If you want your app to work offline and load faster, you can change
10 | // unregister() to register() below. Note this comes with some pitfalls.
11 | // Learn more about service workers: http://bit.ly/CRA-PWA
12 | serviceWorker.unregister();
13 |
--------------------------------------------------------------------------------
/src/logo2.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Next Animation:
6 | The Cake (REMAKE)
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/serviceWorker.js:
--------------------------------------------------------------------------------
1 | // This optional code is used to register a service worker.
2 | // register() is not called by default.
3 |
4 | // This lets the app load faster on subsequent visits in production, and gives
5 | // it offline capabilities. However, it also means that developers (and users)
6 | // will only see deployed updates on subsequent visits to a page, after all the
7 | // existing tabs open on the page have been closed, since previously cached
8 | // resources are updated in the background.
9 |
10 | // To learn more about the benefits of this model and instructions on how to
11 | // opt-in, read http://bit.ly/CRA-PWA
12 |
13 | const isLocalhost = Boolean(
14 | window.location.hostname === 'localhost' ||
15 | // [::1] is the IPv6 localhost address.
16 | window.location.hostname === '[::1]' ||
17 | // 127.0.0.1/8 is considered localhost for IPv4.
18 | window.location.hostname.match(
19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
20 | )
21 | );
22 |
23 | export function register(config) {
24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
25 | // The URL constructor is available in all browsers that support SW.
26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
27 | if (publicUrl.origin !== window.location.origin) {
28 | // Our service worker won't work if PUBLIC_URL is on a different origin
29 | // from what our page is served on. This might happen if a CDN is used to
30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374
31 | return;
32 | }
33 |
34 | window.addEventListener('load', () => {
35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
36 |
37 | if (isLocalhost) {
38 | // This is running on localhost. Let's check if a service worker still exists or not.
39 | checkValidServiceWorker(swUrl, config);
40 |
41 | // Add some additional logging to localhost, pointing developers to the
42 | // service worker/PWA documentation.
43 | navigator.serviceWorker.ready.then(() => {
44 | console.log(
45 | 'This web app is being served cache-first by a service ' +
46 | 'worker. To learn more, visit http://bit.ly/CRA-PWA'
47 | );
48 | });
49 | } else {
50 | // Is not localhost. Just register service worker
51 | registerValidSW(swUrl, config);
52 | }
53 | });
54 | }
55 | }
56 |
57 | function registerValidSW(swUrl, config) {
58 | navigator.serviceWorker
59 | .register(swUrl)
60 | .then(registration => {
61 | registration.onupdatefound = () => {
62 | const installingWorker = registration.installing;
63 | if (installingWorker == null) {
64 | return;
65 | }
66 | installingWorker.onstatechange = () => {
67 | if (installingWorker.state === 'installed') {
68 | if (navigator.serviceWorker.controller) {
69 | // At this point, the updated precached content has been fetched,
70 | // but the previous service worker will still serve the older
71 | // content until all client tabs are closed.
72 | console.log(
73 | 'New content is available and will be used when all ' +
74 | 'tabs for this page are closed. See http://bit.ly/CRA-PWA.'
75 | );
76 |
77 | // Execute callback
78 | if (config && config.onUpdate) {
79 | config.onUpdate(registration);
80 | }
81 | } else {
82 | // At this point, everything has been precached.
83 | // It's the perfect time to display a
84 | // "Content is cached for offline use." message.
85 | console.log('Content is cached for offline use.');
86 |
87 | // Execute callback
88 | if (config && config.onSuccess) {
89 | config.onSuccess(registration);
90 | }
91 | }
92 | }
93 | };
94 | };
95 | })
96 | .catch(error => {
97 | console.error('Error during service worker registration:', error);
98 | });
99 | }
100 |
101 | function checkValidServiceWorker(swUrl, config) {
102 | // Check if the service worker can be found. If it can't reload the page.
103 | fetch(swUrl)
104 | .then(response => {
105 | // Ensure service worker exists, and that we really are getting a JS file.
106 | const contentType = response.headers.get('content-type');
107 | if (
108 | response.status === 404 ||
109 | (contentType != null && contentType.indexOf('javascript') === -1)
110 | ) {
111 | // No service worker found. Probably a different app. Reload the page.
112 | navigator.serviceWorker.ready.then(registration => {
113 | registration.unregister().then(() => {
114 | window.location.reload();
115 | });
116 | });
117 | } else {
118 | // Service worker found. Proceed as normal.
119 | registerValidSW(swUrl, config);
120 | }
121 | })
122 | .catch(() => {
123 | console.log(
124 | 'No internet connection found. App is running in offline mode.'
125 | );
126 | });
127 | }
128 |
129 | export function unregister() {
130 | if ('serviceWorker' in navigator) {
131 | navigator.serviceWorker.ready.then(registration => {
132 | registration.unregister();
133 | });
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/src/styles/index.css:
--------------------------------------------------------------------------------
1 | :root {
2 | --main-color: #282c34;
3 | --white: #fff;
4 | --mistyrose: #ffe4e1;
5 | --btn-color: #db3927;
6 | --coral: #ff7f50;
7 | }
8 |
9 | html {
10 | scroll-behavior: smooth;
11 | }
12 | body {
13 | background-color: var(--mistyrose);
14 | display: grid;
15 | margin: 0;
16 | padding: 0;
17 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
18 | "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
19 | sans-serif;
20 | -webkit-font-smoothing: antialiased;
21 | -moz-osx-font-smoothing: grayscale;
22 | }
23 |
24 | .App {
25 | text-align: center;
26 | }
27 |
28 | .App-logo {
29 | animation: App-logo-spin infinite 20s linear;
30 | height: 15vmin;
31 | }
32 |
33 | @keyframes App-logo-spin {
34 | from {
35 | transform: rotate(0deg);
36 | }
37 | to {
38 | transform: rotate(360deg);
39 | }
40 | }
41 |
42 | .App-header {
43 | background-color: var(--main-color);
44 | min-height: 10vh;
45 | display: flex;
46 | flex-direction: column;
47 | align-items: center;
48 | justify-content: center;
49 | color: var(--white);
50 | }
51 |
52 | .remove-txt-btn {
53 | background-color: var(--btn-color);
54 | }
55 |
56 | .meme-library {
57 | padding: 1rem;
58 | /* background-color: #f3f3f3; */
59 | display: grid;
60 | grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
61 | grid-gap: 0.5rem;
62 | }
63 |
64 | .current-image {
65 | min-width: 300px;
66 | padding: 0.5rem;
67 | }
68 | .text-form {
69 | padding: 1rem;
70 | }
71 | .text-form input {
72 | width: 400px;
73 | }
74 |
75 | .footer {
76 | background-color: var(--main-color);
77 | color: var(--white);
78 | height: 5rem;
79 | display: grid;
80 | align-items: center;
81 | }
82 |
83 | .footer a,
84 | .remove-txt-btn {
85 | margin: 20px;
86 | text-decoration: none;
87 | background-color: var(--btn-color);
88 | color: var(--white);
89 | text-transform: uppercase;
90 | padding: 10px 16px;
91 | border-radius: 10px;
92 | right: 100px;
93 | border: 0;
94 | }
95 |
96 | .footer a:hover,
97 | .remove-txt-btn:hover {
98 | background-color: var(--coral);
99 | color: var(--mistyrose);
100 | }
101 |
102 | /* @media (min-width: 1200px) {
103 | } */
104 |
--------------------------------------------------------------------------------