Skip to content

Commit

Permalink
v1.59.0 GDのバージョンチェックを省略。GDが使えるかどうかのチェックを thumbnail_gd.inc.phpのクラス内へ。
Browse files Browse the repository at this point in the history
  • Loading branch information
satopian committed Nov 24, 2024
1 parent b6eff87 commit edf51e7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 42 deletions.
35 changes: 3 additions & 32 deletions petitnote/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function aikotoba_required_to_view($required_flag=false){
if(!aikotoba_valid()){
$templete='aikotoba.html';
include __DIR__.'/'.$skindir.$templete;
exit;//return include では処理が止まらない。
exit();//return include では処理が止まらない。
}
}

Expand Down Expand Up @@ -766,7 +766,7 @@ function error($str,$historyback=true){

$templete='error.html';
include __DIR__.'/'.$skindir.$templete;
exit;
exit();
}
//csrfトークンを作成
function get_csrf_token(){
Expand Down Expand Up @@ -851,7 +851,7 @@ function check_AsyncRequest($upfile='') {
//Paintの画像差し換えの時はAsyncリクエストを継続
if(!$paint_picrep && ($http_x_requested_with || $asyncflag)){//非同期通信ならエラーチェックだけすませて処理中断。通常フォームでやりなおし。
safe_unlink($upfile);
exit;
exit();
}
}

Expand Down Expand Up @@ -1169,35 +1169,6 @@ function check_pch_ext ($filepath,$options = []) {
return '';
}

//GD版が使えるかチェック
function gd_check(){
$check = ["ImageCreate","ImageCopyResized","ImageCreateFromJPEG","ImageJPEG","ImageDestroy"];

//最低限のGD関数が使えるかチェック
if(!(get_gd_ver() && (ImageTypes() & IMG_JPG))){
return false;
}
foreach ( $check as $cmd ) {
if(!function_exists($cmd)){
return false;
}
}
return true;
}

//gdのバージョンを調べる
function get_gd_ver(){
if(function_exists("gd_info")){
$gdver=gd_info();
$phpinfo=(string)$gdver["GD Version"];
$end=strpos($phpinfo,".");
$phpinfo=substr($phpinfo,0,$end);
$length = strlen($phpinfo)-1;
$phpinfo=substr($phpinfo,$length);
return $phpinfo;
}
return false;
}
// 古いスレッドへの投稿を許可するかどうか
function check_elapsed_days ($postedtime) {
global $elapsed_days;
Expand Down
13 changes: 7 additions & 6 deletions petitnote/index.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
//Petit Note (c)さとぴあ @satopian 2021-2024
//1スレッド1ログファイル形式のスレッド式画像掲示板
$petit_ver='v1.58.8';
$petit_lot='lot.20241122';
$petit_ver='v1.59.0';
$petit_lot='lot.20241124';
$lang = ($http_langs = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '')
? explode( ',', $http_langs )[0] : '';
$en= (stripos($lang,'ja')!==0);
Expand Down Expand Up @@ -697,8 +697,10 @@ function post(){
$data['title'] = $sub;
if($imgfile){
$data['option'][] = [NOTICE_MAIL_IMG,$root_url.IMG_DIR.$imgfile];//拡張子があったら
}
if(is_file(THUMB_DIR.$time.'s.jpg')){
}
if(is_file(THUMB_DIR.$time.'s.webp')){
$data['option'][] = [NOTICE_MAIL_THUMBNAIL,$root_url.THUMB_DIR.$time.'s.webp'];
}elseif(is_file(THUMB_DIR.$time.'s.jpg')){
$data['option'][] = [NOTICE_MAIL_THUMBNAIL,$root_url.THUMB_DIR.$time.'s.jpg'];
}
if($resto){
Expand Down Expand Up @@ -799,8 +801,7 @@ function paint(){
$img_klecks = $pchup;
} elseif(in_array($pchext, ['gif','jpg','jpeg','png','webp']) && in_array($mime_type, ['image/gif', 'image/jpeg', 'image/png','image/webp'])){
$file_name=pathinfo($pchup,PATHINFO_FILENAME);
$basename_pchup=basename($pchup);
thumbnail_gd::thumb(TEMP_DIR,$basename_pchup,$time,$max_px,$max_px,['toolarge'=>true]);
thumbnail_gd::thumb(TEMP_DIR,$pchup,$time,$max_px,$max_px,['toolarge'=>true]);
list($picw,$pich) = getimagesize($pchup);
$imgfile = $pchup;
$anime = false;
Expand Down
2 changes: 1 addition & 1 deletion petitnote/template/basic/error.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ <h1 class="title"><a href="./"><?=h($boardname)?></a></h1>
</div>
</body>
</html>
<?php exit;?>

26 changes: 23 additions & 3 deletions petitnote/thumbnail_gd.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// https://paintbbs.sakura.ne.jp/
// originalscript (C)SakaQ 2005 http://www.punyu.net/php/

$thumbnail_gd_ver=20241117;
$thumbnail_gd_ver=20241124;
defined('PERMISSION_FOR_DEST') or define('PERMISSION_FOR_DEST', 0606); //config.phpで未定義なら0606
class thumbnail_gd {

Expand All @@ -15,7 +15,7 @@ public static function thumb($path,$fname,$time,$max_w,$max_h,$options=[]){
if(!is_file($fname)){
return;
}
if(!gd_check()||!function_exists("ImageCreate")||!function_exists("ImageCreateFromJPEG")){
if(!self::gd_check()||!function_exists("ImageCreate")||!function_exists("ImageCreateFromJPEG")){
return;
}
if((isset($options['webp'])||isset($options['thumbnail_webp'])) && !function_exists("ImageWEBP")){
Expand Down Expand Up @@ -46,7 +46,7 @@ public static function thumb($path,$fname,$time,$max_w,$max_h,$options=[]){
};
// 出力画像(サムネイル)のイメージを作成
$exists_ImageCopyResampled = false;
if(function_exists("ImageCreateTrueColor") && get_gd_ver()=="2"){
if(function_exists("ImageCreateTrueColor")){
$im_out = ImageCreateTrueColor($out_w, $out_h);

if(self::isTransparencyEnabled($options, $mime_type)){//透明度を扱う時
Expand Down Expand Up @@ -94,6 +94,26 @@ public static function thumb($path,$fname,$time,$max_w,$max_h,$options=[]){
return false;

}
//GD版が使えるかチェック
private static function gd_check() {
// GDモジュールが有効化されているか
if (!extension_loaded('gd')) {
return false;
}
// GDモジュールが動作可能か
if (!function_exists('gd_info')) {
return false;
}
// JPEGのサポートを確認
if (!(ImageTypes() & IMG_JPG)) {
return false;
}
// JPEG出力関数の存在を確認
if (!function_exists('ImageJPEG')) {
return false;
}
return true;
}
// 透明度の処理を行う必要があるかを判断
private static function isTransparencyEnabled($options, $mime_type) {
// 透明度を扱うオプションが設定されているか確認
Expand Down

0 comments on commit edf51e7

Please sign in to comment.