diff --git a/src/NotoSansJP-Black.ttf b/src/NotoSansJP-Black.ttf deleted file mode 100644 index a3a382b..0000000 Binary files a/src/NotoSansJP-Black.ttf and /dev/null differ diff --git a/src/NotoSansJP-ExtraLight.ttf b/src/NotoSansJP-ExtraLight.ttf deleted file mode 100644 index ed5f164..0000000 Binary files a/src/NotoSansJP-ExtraLight.ttf and /dev/null differ diff --git a/src/funcs/create_language_img.go b/src/funcs/create_language_img.go index a5deb19..48a2de0 100644 --- a/src/funcs/create_language_img.go +++ b/src/funcs/create_language_img.go @@ -10,9 +10,27 @@ import ( func CreateLanguageImg(username string) []LanguageStat { // 言語ごとの色をここで決める colordict := map[string]string{ - "HTML": "#E34F26", - "CSS": "#ffffff", - "Python": "#3498DB", + "HTML": "#ff0000", + "CSS": "#ffa500", + "Python": "#000080", + "JavaScript": "#ffff00", + "TypeScript": "#3cb371", + "R": "#9932cc", + "Go": "#87cefa", + "Scala": "##006400", + "Flutter" :"#4169e1", + "Rust": "#696969", + "assembly": "#ffd700", + "C": "#f0e68c", + "C++": "#ff69b4", + "Objective-C": "#a52a2a", + "Matlab": "#ff6347", + "C#": "#800080", + "Swift": "#800000", + "Kotlin": "#bdb76b", + "Ruby": "#ee82ee", + "PHP": "#808000", + "Java": "#daa520", "others": "#000000", } diff --git a/src/funcs/draw_background.go b/src/funcs/draw_background.go index 70ae02a..2e36c3e 100644 --- a/src/funcs/draw_background.go +++ b/src/funcs/draw_background.go @@ -42,7 +42,7 @@ func DrawBackground(username, level, kind string) { x2, y2 := (13*Width)/100, (25*Height)/100 // テキスト2の座標(テキストの中央に持つ) dc.DrawStringAnchored(text2, float64(x2), float64(y2), 0.5, 0.5) - if err := dc.LoadFontFace("NotoSansJP-ExtraLight.ttf", 30); err != nil { + if err := dc.LoadFontFace("ipaexg.ttf", 30); err != nil { fmt.Println("フォントのロードに失敗しました:", err) } text3 := kind diff --git a/src/funcs/draw_language.go b/src/funcs/draw_language.go index 90cb407..f6720ba 100644 --- a/src/funcs/draw_language.go +++ b/src/funcs/draw_language.go @@ -18,7 +18,6 @@ type LanguageStat struct { func drawRoundedRectangle(dc *gg.Context, x, y, w, h, r float64) { dc.DrawRectangle(x, y, w, h) dc.Fill() - } func GenerateLanguageUsageGraph(languages []LanguageStat, width, height int) ([]byte, error) { @@ -37,7 +36,7 @@ func GenerateLanguageUsageGraph(languages []LanguageStat, width, height int) ([] // 帯グラフの基準点 barX := 40.0 - barY := 100.0 + barY := 120.0 barHeight := 10.0 barWidth := float64(width) - 80.0 diff --git a/src/funcs/merge_all.go b/src/funcs/merge_all.go index 5cb4069..fb6277f 100644 --- a/src/funcs/merge_all.go +++ b/src/funcs/merge_all.go @@ -31,7 +31,7 @@ func loadImage(filename string) (image.Image, error) { //原点(0, 0)は背景画像の左上隅 // すべての画像のパスを受け取り、それらを合成した画像を生成する関数 -func Merge_all(nameImg, statsImg, characterImg, languageImg, dateImg string) { +func Merge_all(nameImg, statsImg, characterImg, languageImg, dateImg ,filepath string) { // 背景画像を黒で生成 // backgroundWidth := 2000 // 背景画像の幅 // backgroundHeight := 1900 // 背景画像の高さ @@ -110,7 +110,7 @@ func Merge_all(nameImg, statsImg, characterImg, languageImg, dateImg string) { } // 合成した画像を保存 - saveImage(backgroundImage, "result.png") + saveImage(backgroundImage, filepath) ResizeImage("result.png", 700, 0) } diff --git a/src/images/background.png b/src/images/background.png index 37b5f9c..6fd4657 100644 Binary files a/src/images/background.png and b/src/images/background.png differ diff --git a/src/images/commits_history.png b/src/images/commits_history.png index 9c49c19..6f16627 100644 Binary files a/src/images/commits_history.png and b/src/images/commits_history.png differ diff --git a/src/images/gauge.png b/src/images/gauge.png index efd0d2c..7c9154b 100644 Binary files a/src/images/gauge.png and b/src/images/gauge.png differ diff --git a/src/images/generate_character.png b/src/images/generate_character.png index af316e0..13393d0 100644 Binary files a/src/images/generate_character.png and b/src/images/generate_character.png differ diff --git a/src/images/language.png b/src/images/language.png index 4205666..c8690b8 100644 Binary files a/src/images/language.png and b/src/images/language.png differ diff --git a/src/images/stats.png b/src/images/stats.png index 3568103..1544587 100644 Binary files a/src/images/stats.png and b/src/images/stats.png differ diff --git a/src/ipaexg.ttf b/src/ipaexg.ttf new file mode 100755 index 0000000..811b9c0 Binary files /dev/null and b/src/ipaexg.ttf differ diff --git a/src/main.go b/src/main.go index 78f0719..8811dce 100644 --- a/src/main.go +++ b/src/main.go @@ -2,12 +2,12 @@ package main import ( "fmt" + "github.com/tomoish/readme/funcs" + "github.com/tomoish/readme/graphs" "log" "net/http" "strconv" - - "github.com/tomoish/readme/funcs" - "github.com/tomoish/readme/graphs" + "os" ) // func handler(w http.ResponseWriter, r *http.Request) { @@ -115,12 +115,22 @@ func getHistoryHandler(w http.ResponseWriter, r *http.Request) { // } // 画像生成エンドポイント -func createHandler(w http.ResponseWriter, r *http.Request) { + +func createhandler(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Cache-Control", "public, max-age=3600") + queryValues := r.URL.Query() username := queryValues.Get("username") if r.Method == http.MethodGet { // GETリクエストの処理 + // 一意の画像ファイル名の生成(例: ユーザー名とタイムスタンプを組み合わせる) + imageFileName := fmt.Sprintf("result_%s.png", username) + // 画像ファイルの存在チェック + if _, err := os.Stat(imageFileName); os.IsNotExist(err) { + // 画像が存在しない場合は、新たに生成 + + // 画像生成の処理... // stats取得と画像生成 stats := funcs.CreateUserStats(username) total := stats.TotalStars + stats.ContributedTo + stats.TotalIssues + stats.TotalPRs + stats.TotalCommits @@ -148,17 +158,17 @@ func createHandler(w http.ResponseWriter, r *http.Request) { fmt.Println(err) } - // 全て合体 - funcs.Merge_all("./images/background.png", "./images/stats.png", "./images/generate_character.png", "./images/language.png", "./images/commits_history.png") + // 全て合体して画像を保存 + funcs.Merge_all("./images/background.png", "./images/stats.png", "./images/generate_character.png", "./images/language.png", "./images/commits_history.png", imageFileName) + } + + // キャッシュ制御ヘッダーを設定 + w.Header().Set("Cache-Control", "public, max-age=3600") + + // 生成済みの画像ファイルをクライアントに返す + http.ServeFile(w, r, imageFileName) + - http.ServeFile(w, r, "./result.png") - // } else if r.Method == http.MethodPost { - // // POSTリクエストの処理 - // totalCommitContributions, totalStarredRepositories, totalIssueContributions, totalPullRequestContributions, totalRepositoryContributions, err := funcs.FetchData(username) - // if err != nil { - // fmt.Println(err) - // return - // } } else { http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) @@ -204,3 +214,10 @@ func main() { // fmt.Println("totalRepositoryContributions: ", totalRepositoryContributions) fmt.Println(funcs.JudgeProfession("C+", []string{"Go"}, []float64{100})) } + // } else if r.Method == http.MethodPost { + // // POSTリクエストの処理 + // totalCommitContributions, totalStarredRepositories, totalIssueContributions, totalPullRequestContributions, totalRepositoryContributions, err := funcs.FetchData(username) + // if err != nil { + // fmt.Println(err) + // return + // } diff --git a/src/result.png b/src/result.png index 3bccc7a..4bed75a 100644 Binary files a/src/result.png and b/src/result.png differ diff --git a/src/result_kou7306.png b/src/result_kou7306.png new file mode 100644 index 0000000..99f5304 Binary files /dev/null and b/src/result_kou7306.png differ