http://www.adidas.co.uk/help-topics-size_charts.html
남자 기준
UK : 8
EU(FR) : 42
US : 8.5
JP : 265
KR : 265
http://www.adidas.co.uk/help-topics-size_charts.html
남자 기준
UK : 8
EU(FR) : 42
US : 8.5
JP : 265
KR : 265
web.xml 에 등록
<servlet>
<servlet-name>CaptchaServlet</servlet-name>
<servlet-class>com.common.util.CaptchaServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CaptchaServlet</servlet-name>
<url-pattern>/captcha</url-pattern>
</servlet-mapping>
package com.common.util;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Iterator;
import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class CaptchaServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
Log log = LogFactory.getLog(CaptchaServlet.class);
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession(true);
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setDateHeader("Max-Age", 0);
response.setContentType("image/jpg");
BufferedImage bufferedImage = null;
Graphics2D g = null;
try {
Color textColor = Color.decode("#2e2e2e");
Font textFont = new Font("arial Tahoma Sans-serif", Font.BOLD, 22);
int charsToPrint = 5;
int width = request.getParameter("width") != null ? Integer.parseInt(request.getParameter("width")) : 150;
int height = request.getParameter("height") != null ? Integer.parseInt(request.getParameter("height")) : 35;
float horizMargin = 12.0f;
float imageQuality = 1.0f; // max is 1.0 (this is for jpeg)
double rotationRange = 0.1; // this is radians
bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
g = (Graphics2D) bufferedImage.getGraphics();
//Draw an oval
//g.setColor(Color.decode("#ECEAEA"));
g.fillRect(0, 0, width, height);
g.setColor(textColor);
g.setFont(textFont);
FontMetrics fontMetrics = g.getFontMetrics();
int maxAdvance = fontMetrics.getMaxAdvance();
int fontHeight = fontMetrics.getHeight();
// i removed 1 and l and i because there are confusing to users...
// Z, z, and N also get confusing when rotated
// 0, O, and o are also confusing...
// lowercase G looks a lot like a 9 so i killed it
// this should ideally be done for every language...
// i like controlling the characters though because it helps prevent confusion
String elegibleChars = "ABCDEFGHJKLMPQRSTUVWXY23456789";
//String elegibleChars = "AEFHKLPRTX12345678";
//String elegibleChars = "0123456789";
char[] chars = elegibleChars.toCharArray();
float spaceForLetters = -horizMargin * 5 + width;
float spacePerChar = spaceForLetters / (charsToPrint - 1.5f);
AffineTransform transform = g.getTransform();
StringBuffer finalString = new StringBuffer();
for (int i = 0; i < charsToPrint; i++) {
double randomValue = Math.random();
int randomIndex = (int) Math.round(randomValue * (chars.length - 1));
char characterToShow = chars[randomIndex];
finalString.append(characterToShow);
// this is a separate canvas used for the character so that
// we can rotate it independently
int charImageWidth = maxAdvance * 2;
int charImageHeight = fontHeight * 2;
int charWidth = fontMetrics.charWidth(characterToShow);
int charDim = Math.max(maxAdvance, fontHeight);
int halfCharDim = (int) (charDim / 2);
BufferedImage charImage = null;
Graphics2D charGraphics = null;
try {
charImage = new BufferedImage(charDim, charDim, BufferedImage.TYPE_INT_ARGB);
charGraphics = charImage.createGraphics();
charGraphics.translate(halfCharDim, halfCharDim);
double angle = (Math.random() - 0.5) * rotationRange;
charGraphics.transform(AffineTransform.getRotateInstance(angle));
charGraphics.translate(-halfCharDim, -halfCharDim);
charGraphics.setColor(textColor);
charGraphics.setFont(textFont);
int charX = (int) (0.5 * charDim - 0.5 * charWidth);
charGraphics.drawString("" + characterToShow, charX, (int) ((charDim - fontMetrics.getAscent()) / 2 + fontMetrics.getAscent()));
float x = horizMargin + spacePerChar * (i) - charDim / 4.0f;
int y = (int) ((height - charDim) / 2);
//System.out.println("x=" + x + " height=" + height + " charDim=" + charDim + " y=" + y + " advance=" + maxAdvance + " fontHeight=" + fontHeight + " ascent=" + fontMetrics.getAscent());
g.drawImage(charImage, (int) x, y, charDim, charDim, null, null);
} finally {
try {
charGraphics.dispose();
} catch (Exception ex) {}
try {
charImage.flush();
} catch (Exception ex) {}
}
}
System.out.println(finalString);
log.info("captcha string : " + finalString);
//Write the image as a jpg
Iterator iter = ImageIO.getImageWritersByFormatName("JPG");
if (iter.hasNext()) {
ImageWriter writer = null;
javax.imageio.stream.ImageOutputStream imageOutputStream = null;
javax.servlet.ServletOutputStream servletOutputStream = null;
try {
writer = (ImageWriter) iter.next();
ImageWriteParam iwp = writer.getDefaultWriteParam();
iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
iwp.setCompressionQuality(imageQuality);
servletOutputStream = response.getOutputStream();
imageOutputStream = ImageIO.createImageOutputStream(servletOutputStream);
writer.setOutput(imageOutputStream);
IIOImage imageIO = new IIOImage(bufferedImage, null, null);
writer.write(null, imageIO, iwp);
} catch (Exception ex) {
writer.abort();
} finally {//modified to prevent too many open files error
if (writer != null) {
writer.dispose();
}
try {
imageOutputStream.close();
} catch (Exception ex) {}
try {
servletOutputStream.close();
} catch (Exception ex) {}
}
} else {
log.error("CaptchaErr No Encoder Found For JSP");
throw new RuntimeException("no encoder found for jsp");
}
//ImageIO.write(bufferedImage, "jpg", response.getOutputStream());
// let's stick the final string in the session
request.getSession(true).setAttribute("captcha", finalString.toString());
} catch (Exception ioe) {
log.error("Captcha Error : " + ioe.getMessage());
throw new RuntimeException("Unable to build image", ioe);
} finally {
try {
g.dispose();
} catch (Exception ex) {}
try {
bufferedImage.flush();
} catch (Exception ex) {}
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
processRequest(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
processRequest(request, response);
}
}
mssql 에서 text 타입의 컬럼에 값을 아무것도 넣지 않으면 형식 오류가 발생한다.
text 타입은 이제 사용하지 않을 예정이란다.
중요 |
---|
적용 대상: SQL Server(SQL Server 2008 부터 current version 까지), Windows Azure SQL 데이터베이스(최초 릴리스 부터 현재 릴리스 까지) |
ntext, text 및 image(Transact-SQL)
https://msdn.microsoft.com/ko-kr/library/ms187993(v=sql.120).aspx
text 대신 nvarchar(max), varchar(max)를 사용하자.
nginx 설치 할 때 ngx_http_image_filter_module
필요
location /pics {
alias /var/www/pics;
set $width 500;
set $height 500;
set $dimens "";
if ($uri ~* "^/pics_(\d+)x(\d+)/(.*)" ) {
set $width $1;
set $height $2;
set $image_path $3;
set $demins "$1x$2";
}
if ($uri ~* "^/pics/(.*)" ) {
set $image_path $1;
}
set $image_uri image_resize/$image_path?width=$width&height=$height;
if (!-f $request_filename) {
proxy_pass http://192.168.0.100/$image_uri;
break;
}
proxy_store /var/www/pics/$demins/$image_path;
proxy_store_access user:rw group:rw all:r;
proxy_temp_path /tmp/images;
proxy_set_header Host $host;
}
location /image_resize {
alias /var/www/pics;
image_filter resize $arg_width $arg_height;
image_filter_jpeg_quality 75;
image_filter_buffer 5m; // 최대 이미지 용량 기본은 1m
# allow 127.0.0.0/8;
# allow 192.168.0.1/32;
# deny all;
}
}
참고
http://nginx.org/en/docs/http/ngx_http_image_filter_module.html
원래 이미지
http://192.168.0.100/pics/sbg.png
썸네일 이미지
http://192.168.0.100/pics_500x500/sbg.png
At Sturm we build web apps that perform beautifully on both tiny mobile devices and huge desktop monitors. To achieve these, we use Nginx to resize images on-the-fly. This approach was used in our recent Course Finder project with Federation University.
The Nginx web server comes with a handy image filter module, but most tutorials don't configure it with performance in mind. Performance means caching.
Let's start with the basics:
server {
# Basic image resizing server, no caching.
server_name example.com;
location ~ "^/media/(?<width>\d+)/(?<image>.+)$" {
alias /var/www/images/$image;
image_filter resize $width -;
image_filter_jpeg_quality 75;
image_filter_buffer 8M;
}
}
Don't forget to reload your Nginx configuration:
$ sudo service nginx force-reload
This server block will respond to a request like http://example.com/media/768/mountains.jpg
with the file/var/www/images/mountains.jpg
. It will resize the image down to 768 pixels wide if necessary and compress it using JPEG quality 75. Requests where the original image is 8MB will be rejected.
Unfortunately our simple example doesn't perform so well, since it does a resize for every single request. Let's test it using Apache Bench (from apache2-utils
on a Debian-based GNU/Linux). We'll make 100 requests using 5 concurrent connections:
$ ab -n 100 -c 5 http://example.com/media/768/mountains.jpg
...
Requests per second: 4.14 [#/sec] (mean)
...
Oh no, only four requests per second!
The solution is to cache the resized image so that the work is only done once a day. Since Nginx can't cache and resize at the same time, we'll need a trick. That trick is to use two server blocks. The first will be an internal-onlyserver that resize images. The second will be a public server that proxies requests to our internal server and then caches the result:
server {
# Internal image resizing server.
server_name localhost;
listen 8888;
location ~ "^/media/(?<width>\d+)/(?<image>.+)$" {
alias /var/www/images/$image;
image_filter resize $width -;
image_filter_jpeg_quality 75;
image_filter_buffer 8M;
}
}
proxy_cache_path /tmp/nginx-images-cache/ levels=1:2 keys_zone=images:10m inactive=24h max_size=100m;
server {
# Public-facing cache server.
server_name example.com;
# Only serve widths of 768 or 1920 so we can cache effectively.
location ~ "^/media/(?<width>(768|1920))/(?<image>.+)$" {
# Proxy to internal image resizing server.
proxy_pass http://localhost:8888/media/$width/$image;
proxy_cache images;
proxy_cache_valid 200 24h;
}
location /media {
# Nginx needs you to manually define DNS resolution when using
# variables in proxy_pass. Creating this dummy location avoids that.
# The error is: "no resolver defined to resolve localhost".
proxy_pass http://localhost:8888/;
}
}
Now that we're caching the resized images, Apache Bench shows a slow first request, but thereafter serves over 7000 requests per second!
server {
listen 80;
server_name a.test.com;
rewrite ^(.*) https://$host$1 permanent;
}
server {
listen 0.0.0.0:8006;
server_name _;
ssl on;
ssl_certificate cert/1_domain.tld_bundle.crt;
ssl_certificate_key cert/2_domain.tld.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+EXP;
location / {
proxy_pass https://127.0.0.1:8086;
}
}
<Connector URIEncoding="UTF-8" port="7880" protocol="HTTP/1.1"
connectionTimeout="20000"
proxyPort="443"
scheme="https"
redirectPort="7843" />
카멜케이스로 된 문자를 언더바문자로 변경
String regex = "([a-z])([A-Z]+)";
String replacement = "$1_$2";
System.out.println("CamelCaseToSomethingElse"
.replaceAll(regex, replacement)
.toLowerCase());
editplus에서도 사용 가능.
찾을말 : ([a-z])([A-Z]+)
바꿀말 : $1_$2
정규식 체크.
Hex Opacity Values
for (double i = 1; i >= 0; i -= 0.01) {
i = Math.round(i * 100) / 100.0d;
int alpha = (int) Math.round(i * 255);
String hex = Integer.toHexString(alpha).toUpperCase();
if (hex.length() == 1) hex = "0" + hex;
int percent = (int) (i * 100);
System.out.println(String.format("%d%% — %s", percent, hex));
}
100% — FF
99% — FC
98% — FA
97% — F7
96% — F5
95% — F2
94% — F0
93% — ED
92% — EB
91% — E8
90% — E6
89% — E3
88% — E0
87% — DE
86% — DB
85% — D9
84% — D6
83% — D4
82% — D1
81% — CF
80% — CC
79% — C9
78% — C7
77% — C4
76% — C2
75% — BF
74% — BD
73% — BA
72% — B8
71% — B5
70% — B3
69% — B0
68% — AD
67% — AB
66% — A8
65% — A6
64% — A3
63% — A1
62% — 9E
61% — 9C
60% — 99
59% — 96
58% — 94
57% — 91
56% — 8F
55% — 8C
54% — 8A
53% — 87
52% — 85
51% — 82
50% — 80
49% — 7D
48% — 7A
47% — 78
46% — 75
45% — 73
44% — 70
43% — 6E
42% — 6B
41% — 69
40% — 66
39% — 63
38% — 61
37% — 5E
36% — 5C
35% — 59
34% — 57
33% — 54
32% — 52
31% — 4F
30% — 4D
29% — 4A
28% — 47
27% — 45
26% — 42
25% — 40
24% — 3D
23% — 3B
22% — 38
21% — 36
20% — 33
19% — 30
18% — 2E
17% — 2B
16% — 29
15% — 26
14% — 24
13% — 21
12% — 1F
11% — 1C
10% — 1A
9% — 17
8% — 14
7% — 12
6% — 0F
5% — 0D
4% — 0A
3% — 08
2% — 05
1% — 03
0% — 00