mesektok.com에서 공개 파비콘 생성기 구현 가이드

mesektok.com에서 공개 파비콘 생성기 구현 가이드

이 가이드는 mesektok.com 워드프레스 사이트에서 불특정 다수의 사용자가 파비콘을 생성할 수 있는 기능을 구현하는 과정을 설명합니다.

1. 준비 단계

  1. 워드프레스가 mesektok.com에 설치되어 있는지 확인합니다.
  2. 관리자 권한으로 워드프레스 대시보드에 접속합니다.

2. 플러그인 개발

  1. FTP 또는 파일 관리자를 통해 /wp-content/plugins/ 디렉토리에 접근합니다.
  2. mesektok-public-favicon-generator 폴더를 생성합니다.
  3. 이 폴더 안에 mesektok-public-favicon-generator.php 파일을 생성하고 다음 코드를 입력합니다:

<?php
/*
Plugin Name: MesekTok Public Favicon Generator
Plugin URI: https://mesektok.in/favicon-generator
Description: 불특정 사용자가 파비콘을 생성할 수 있는 공개 플러그인
Version: 1.0
Author: Your Name
Author URI: https://mesektok.in
*/

// 공개 페이지에 파비콘 생성기 추가
function mesektok_add_favicon_generator_page() {
add_rewrite_rule(‘^favicon-generator/?’, ‘index.php?favicon_generator=1’, ‘top’);
}
add_action(‘init’, ‘mesektok_add_favicon_generator_page’);

function mesektok_query_vars($query_vars) {
$query_vars[] = ‘favicon_generator’;
return $query_vars;
}
add_filter(‘query_vars’, ‘mesektok_query_vars’);

function mesektok_favicon_template($template) {
if (get_query_var(‘favicon_generator’) == 1) {
return plugin_dir_path(__FILE__) . ‘favicon-generator-template.php’;
}
return $template;
}
add_filter(‘template_include’, ‘mesektok_favicon_template’);

// 파비콘 생성 로직
function mesektok_generate_favicon() {
if (!empty($_FILES[‘favicon_image’][‘tmp_name’])) {
$upload_dir = wp_upload_dir();
$image = wp_get_image_editor($_FILES[‘favicon_image’][‘tmp_name’]);

if (!is_wp_error($image)) {
$sizes = array(16, 32, 48, 64, 128, 256);
$favicon_files = array();
foreach ($sizes as $size) {
$image->resize($size, $size, true);
$file_name = “favicon-{$size}x{$size}.png”;
$file_path = $upload_dir[‘path’] . ‘/’ . $file_name;
$image->save($file_path);
$favicon_files[] = $file_path;
}

// ZIP 파일 생성
$zip = new ZipArchive();
$zip_file = $upload_dir[‘path’] . ‘/favicon.zip’;
if ($zip->open($zip_file, ZipArchive::CREATE) === TRUE) {
foreach ($favicon_files as $file) {
$zip->addFile($file, basename($file));
}
$zip->close();

// ZIP 파일 다운로드
header(‘Content-Type: application/zip’);
header(‘Content-Disposition: attachment; filename=”favicon.zip”‘);
header(‘Content-Length: ‘ . filesize($zip_file));
readfile($zip_file);

// 임시 파일 삭제
array_map(‘unlink’, $favicon_files);
unlink($zip_file);
exit;
} else {
echo “ZIP 파일 생성에 실패했습니다.”;
}
} else {
echo “파비콘 생성 중 오류가 발생했습니다.”;
}
}
}

// AJAX 핸들러 등록
function mesektok_ajax_generate_favicon() {
mesektok_generate_favicon();
wp_die();
}
add_action(‘wp_ajax_generate_favicon’, ‘mesektok_ajax_generate_favicon’);
add_action(‘wp_ajax_nopriv_generate_favicon’, ‘mesektok_ajax_generate_favicon’);

4. favicon-generator-template.php 파일을 생성하고 다음 코드를 입력합니다:

<?php
get_header();
?>

<div class=”wrap”>
<h1>파비콘 생성기</h1>
<form id=”favicon-form” method=”post” enctype=”multipart/form-data”>
<input type=”file” name=”favicon_image” accept=”image/*” required>
<input type=”submit” value=”파비콘 생성”>
</form>
<div id=”result”></div>
</div>

<script>
jQuery(document).ready(function($) {
$(‘#favicon-form’).on(‘submit’, function(e) {
e.preventDefault();
var formData = new FormData(this);
formData.append(‘action’, ‘generate_favicon’);

$.ajax({
url: ‘<?php echo admin_url(‘admin-ajax.php’); ?>’,
type: ‘POST’,
data: formData,
processData: false,
contentType: false,
success: function(response) {
$(‘#result’).html(‘파비콘이 생성되었습니다. 다운로드가 곧 시작됩니다.’);
var blob = new Blob([response], {type: ‘application/zip’});
var link = document.createElement(‘a’);
link.href = window.URL.createObjectURL(blob);
link.download = ‘favicon.zip’;
link.click();
},
error: function() {
$(‘#result’).html(‘파비콘 생성 중 오류가 발생했습니다.’);
}
});
});
});
</script>

<?php
get_footer();
?>

3. 플러그인 활성화

  1. 워드프레스 관리자 대시보드에서 ‘플러그인’ 메뉴로 이동합니다.
  2. ‘MesekTok Public Favicon Generator’ 플러그인을 찾아 활성화합니다.

4. 파비콘 생성기 사용

  1. 사이트 방문자는 https://mesektok.in/favicon-generator/에 접속하여 파비콘 생성기를 사용할 수 있습니다.
  2. 이미지를 업로드하고 ‘파비콘 생성’ 버튼을 클릭합니다.
  3. 생성된 파비콘 파일들이 ZIP 형식으로 다운로드됩니다.

5. 주의사항

  • 이 구현은 불특정 다수의 사용자가 파비콘을 생성할 수 있게 합니다. 별도의 로그인이 필요하지 않습니다.
  • 서버 리소스 사용을 고려하여 적절한 제한(예: 파일 크기, 생성 빈도)을 설정하는 것이 좋습니다.
  • 생성된 파일은 즉시 삭제되므로 서버 공간을 장기적으로 차지하지 않습니다.

이 가이드를 따라 구현하면 mesektok.com에서 누구나 사용할 수 있는 파비콘 생성기를 제공할 수 있습니다.

Leave a Comment