Skip to content

Examples

Gökdeniz edited this page Oct 13, 2019 · 27 revisions

You can send your example codes in my Discord server: https://discord.gg/ayvQQtq

Example 1 - Resizing Images

get image from url "https://image.ibb.co/fcOq9H/8YjB0k.jpg" and store the result to variable {_image}
set {_width} to width of {_image}
set {_height} to height of {_image}
resize {_image} to width ({_width} / 2) and height ({_height} / 2) and store the result in {_a2}
resize {_image} to width ({_width} / 2) and height ({_height} / 2) using algorithm 5 and store the result in {_a5}
save {_a2} to "algorithm-2.png"
save {_a5} to "algorithm-5.png"

Gets an image from an URL and resizes it to half-sizes using two different algorithms.
Want to see the differences between the algorithms? Base Image - Algorithm 2 - Algorithm 5


Example 2 - Meme Generator

⚠️ This seems to be problematic

This code also registers a custom effect for generate meme code, because custom effects supports delay.
It will register Impact font from the specified file in line 2. It is impact.ttf file in fonts folder in the server folder. The font will be unregistered when the server stops. If you are sure about that Impact font is already installed in the system, you can remove the register font code if you want.
The algorithm supports new lines. So it will create the 2nd line if the text is too long, also will make the text smaller automatically.

The code below must be loaded before using it, also must be loaded after imagesk, so putting it in a sk file named !memeGenerator.sk is fine.

Download Impact.ttf: https://drive.google.com/file/d/1nfX3M46ehhiiyt8hPC2E3eR1NU2ohBq3/view?usp=sharing

Code

on load:
	register font from file "fonts/impact.ttf"

effect (generate|create|make) meme (with|using) [(image|img)] %object% (and [with]|[and] with) lines %strings%:
	trigger:
		delay the current effect
		set {_image} to expression-1
		set {_imageWidth} to image width of {_image}
		set {_imageHeight} to image height of {_image}
		set {_lines::*} to expressions-2
		create an image text with id "line"
		set font of "line" to "Impact"
		set bold state of "line" to on
		loop {_lines::*}:
			add 1 to {_line}
			if {_line} is not 1 or 2:
				stop loop
			if loop-value is not "":
				delete {_line2}
				set {_x} to loop-value
				delete {_spaces::*}
				loop numbers between 0 and length of {_x} - 1:
					if "%{_x}.charAt(loop-number)%" is " ":
						add loop-number to {_spaces::*}
				if size of {_spaces::*} is greater than 4:
					set {_d} to rounded up size of {_spaces::*} / 2
					set {_x} to "%subtext of {_x} from character 1 to {_spaces::%{_d}%}%\n%subtext of {_x} from character {_spaces::%{_d}%} + 2 to length of {_x}%"
				set {_texts::*} to ...{_x}.split("\n|\\n")
				if size of {_texts::*} is greater than 1:
					loop {_texts::*}:
						add length of loop-value-2 to {_length::*}
					set {_length::*} to sorted {_length::*}
					loop {_texts::*}:
						add 1 to {_longestLine}
						if length of loop-value-2 is last element of {_length::*}:
							stop loop
				else:
					set {_longestLine} to 1
				loop {_texts::*}:
					add 1 to {_line2}
					if {_line2} is 1:
						set text of "line" to {_texts::%{_longestLine}%} in upper case
						set size of "line" to 85
						set outline width of "line" to 3.6
						set {_textWidth} to width of "line"
						while {_textWidth} is greater than {_imageWidth}:
							remove 2 from size of "line"
							remove 0.1 from outline width of "line"
							set {_textWidth} to width of "line"
					set text of "line" to "%loop-value-2%" in upper case
					set {_textWidth} to width of "line"
					set {_x} to ({_imageWidth} - {_textWidth}) / 2
					if {_line} and {_line2} is 1:
						set {_y} to 10
					else if {_line} is 2:
						set {_y} to {_imageHeight} - (ascent of "line" + 20)
					if {_line2} is not 1:
						if {_line} is 1:
							add height of "line" - 8 to {_y}
					if {_line} is not 1:
						loop size of {_texts::*} - {_line2} times:
							remove height of "line" - 8 from {_y}
					if outline width of "line" is -0:
						set outline width of "line" to 0
					write "line" on {_image} at location {_x}, {_y}
		delete image text with id "line"
		continue


Syntax

(generate|create|make) meme (with|using) [(image|img)] %image% (and [with]|[and] with) lines %texts%
Example Usage

get image from url "https://image.ibb.co/mqxW9H/disaster_girl.jpg"
make meme using the image with lines "my neighbors used to listen to justin bieber" and "now they don't"
save the image to "memes/justin.png"


The example code will create this meme: https://image.ibb.co/edtSGx/justin.png Looks pretty good.


Example 3 - Discord User Stats Card

Simple code that generates Discord user stats card. This is a template, not a full Discord stats system. But it calculates something such as size of the progress bar.

Code: Click Here

Preview

Preview

See Also: Upload Image to Discord Effect


Example 4 - Rotating Text

create an image with width 256 and height 256 with background color black

create new image text with id "test" with content "0 degree"
set size of "test" to 30
set font of "test" to "Comic Sans MS"
set {_textWidth} to width of "test"
set {_textHeight} to height of "test"

write image text with id "test" on the image at location (128 - {_textWidth} / 2), (128 - {_textHeight} / 2)

set content of "test" to "20 degree"
write image text with id "test" on the image at location (128 - {_textWidth} / 2), (128 - {_textHeight} / 2) with rotation 20 degree angle

set content of "test" to "90 degree"
write image text with id "test" on the image at location (128 - {_textWidth} / 2), (128 - {_textHeight} / 2) with rotation 90 degree angle

set content of "test" to "-45 degree"
write image text with id "test" on the image at location (128 - {_textWidth} / 2), (128 - {_textHeight} / 2) with rotation -45 degree angle

Preview

PNG

GIF


Example 5 - Rotating Objects with a Specified Origin Location

create an image with width 512 and height 512 with background color black
draw circle with radius 5 and color light green on the image at location 256, 256

create new image text with id "test" with content "imagesk"
set size of "test" to 30
set font of "test" to "Comic Sans MS"
set {_textWidth} to width of "test"
set {_textHeight} to height of "test"

loop 0, 45, 90, 135, 180, 225, 270 and 315:
    write image text with id "test" on the image at location 300, (256 - {_textHeight}) - 10 with rotation loop-number degree using origin location 256, 256 
    draw line with width 10 with rotation loop-number degree using origin location 256, 256 on the image from location 300, 256 to (300 + {_textWidth}), 256

(used location of the green dot as the origin location)

Preview

Open Spoiler


Example 6 - Using Linear Gradients

on load:
	create an image with width 500 and height 500 with background color gray
	
	set {_gradient} to reflected linear gradient with colors black and white from location 0, 250 to 50, 250
	draw a rectangle with width 500 and height 250 with paint {_gradient} on the image at location 0, 30
	
	set {_gradient} to repeating linear gradient with colors purple, blue and orange from location 30, 30 to 80, 80
	draw line with width 32 with paint {_gradient} on the image from location 30, 30 to 400, 400
	
	set {_gradient} to reflected linear gradient with colors purple, blue and orange from location 30, 70 to 80, 120
	draw line with width 32 with paint {_gradient} on the image from location 30, 80 to 400, 450
	
	set {_gradient} to linear gradient with colors green, purple, blue and orange from location 30, 70 to 80, 120
	draw line with width 32 with paint {_gradient} on the image from location 30, 130 to 400, 500
	
	set {_gradient} to reflected linear gradient with colors red and white from location 0, 250 to 10, 250
	create a new image text with id "test" with content "Testing Stuff"
	set paint of text "test" to {_gradient}
	set size of text "test" to 60 
	set bold state of text "test" to on
	write text "test" on the image at location 0, 420
	
	save the image to "test.png"

Preview

Open Spoiler


Example 7 - Using Radial Gradients

on load:
	create an image with width 500 and height 500 with background color gray
	
	set {_gradient} to reflected radial gradient with colors black and white with radius 30 at location 250, 20
	draw a rectangle with width 500 and height 250 with paint {_gradient} on the image at location 0, 30
	
	set {_gradient} to repeating radial gradient with colors purple, blue and orange with horizontal radius 50 and vertical radius 20 at location 250, 250
	draw line with width 32 with paint {_gradient} on the image from location 30, 30 to 400, 400
	
	set {_gradient} to reflected radial gradient with colors purple, blue and orange with horizontal radius 50 and vertical radius 20 at location 250, 250
	draw line with width 32 with paint {_gradient} on the image from location 30, 80 to 400, 450
	
	set {_gradient} to radial gradient with colors purple, blue and orange with horizontal radius 50 and vertical radius 20 at location 250, 250
	draw line with width 32 with paint {_gradient} on the image from location 30, 130 to 400, 500
	
	set {_gradient} to reflected radial gradient with colors pink, blue, orange with radius 30 at location 50, 380 using focus location 60, 400
	draw a rectangle with width 160 and height 160 with paint {_gradient} on the image at location 0, 300

	create a new image text with id "test" with content "Testing Stuff"
	set size of text "test" to 79
	set bold state of text "test" to on
	set outline width of text "test" to 6
	set {_textWidth} to width of text "test"
	set {_textHeight} to height of text "test"
	set {_gradient} to reflected radial gradient with colors red and white with radius 3 at center location ({_textWidth} / 2), (400 - {_textHeight})
	set paint of text "test" to {_gradient}
	set {_gradient} to reflected radial gradient with colors black and dark gray with radius 2 at center location (20 + {_textWidth} / 2), (400 - {_textHeight})
	set outline paint of text "test" to {_gradient}
	write text "test" on the image at location 20, 400
	
	save the image to "test.png"

Preview

Open Spoiler

Green dot: Main location
Red dot: Focus location