105 lines
3.4 KiB
PHP
105 lines
3.4 KiB
PHP
<?php
|
|
require_once __DIR__ . '/includes/config.php';
|
|
|
|
echo "=== اختبار نظام معالجة الصور ===\n\n";
|
|
|
|
class ImageProcessor {
|
|
private $upload_dir;
|
|
private $cache_dir;
|
|
private $allowed_types;
|
|
private $max_size;
|
|
|
|
public function __construct() {
|
|
$this->upload_dir = __DIR__ . '/uploads/images';
|
|
$this->cache_dir = __DIR__ . '/cache/images';
|
|
$this->allowed_types = ['image/jpeg', 'image/png', 'image/webp'];
|
|
$this->max_size = 5 * 1024 * 1024; // 5MB
|
|
|
|
// إنشاء المجلدات إذا لم تكن موجودة
|
|
foreach ([$this->upload_dir, $this->cache_dir] as $dir) {
|
|
if (!is_dir($dir)) {
|
|
mkdir($dir, 0755, true);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function processTestImage() {
|
|
// إنشاء صورة اختبار
|
|
$width = 800;
|
|
$height = 600;
|
|
$image = imagecreatetruecolor($width, $height);
|
|
|
|
// تلوين الصورة
|
|
$bg_color = imagecolorallocate($image, 240, 240, 240);
|
|
$text_color = imagecolorallocate($image, 50, 50, 50);
|
|
|
|
imagefill($image, 0, 0, $bg_color);
|
|
|
|
// إضافة نص
|
|
$text = "ShubraVeil Test Image";
|
|
$font_size = 5;
|
|
|
|
// حساب موقع النص
|
|
$text_width = imagefontwidth($font_size) * strlen($text);
|
|
$text_height = imagefontheight($font_size);
|
|
|
|
$x = ($width - $text_width) / 2;
|
|
$y = ($height - $text_height) / 2;
|
|
|
|
imagestring($image, $font_size, $x, $y, $text, $text_color);
|
|
|
|
// حفظ الصورة الأصلية
|
|
$original_file = $this->upload_dir . '/test_image.png';
|
|
imagepng($image, $original_file);
|
|
|
|
echo "تم إنشاء صورة الاختبار: " . basename($original_file) . "\n";
|
|
echo "الحجم: " . $this->formatSize(filesize($original_file)) . "\n\n";
|
|
|
|
// إنشاء نسخة مصغرة
|
|
$thumb_width = 150;
|
|
$thumb_height = 150;
|
|
$thumbnail = imagecreatetruecolor($thumb_width, $thumb_height);
|
|
|
|
imagecopyresampled(
|
|
$thumbnail, $image,
|
|
0, 0, 0, 0,
|
|
$thumb_width, $thumb_height,
|
|
$width, $height
|
|
);
|
|
|
|
$thumb_file = $this->cache_dir . '/thumb_test_image.png';
|
|
imagepng($thumbnail, $thumb_file);
|
|
|
|
echo "تم إنشاء النسخة المصغرة: " . basename($thumb_file) . "\n";
|
|
echo "الحجم: " . $this->formatSize(filesize($thumb_file)) . "\n";
|
|
|
|
// تنظيف الذاكرة
|
|
imagedestroy($image);
|
|
imagedestroy($thumbnail);
|
|
|
|
return [
|
|
'original' => $original_file,
|
|
'thumbnail' => $thumb_file
|
|
];
|
|
}
|
|
|
|
private function formatSize($size) {
|
|
$units = ['B', 'KB', 'MB', 'GB'];
|
|
$power = $size > 0 ? floor(log($size, 1024)) : 0;
|
|
return number_format($size / pow(1024, $power), 2, '.', ',') . ' ' . $units[$power];
|
|
}
|
|
}
|
|
|
|
try {
|
|
$processor = new ImageProcessor();
|
|
$files = $processor->processTestImage();
|
|
|
|
echo "\nاختبار اكتمل بنجاح!\n";
|
|
echo "الملفات التي تم إنشاؤها:\n";
|
|
echo "- الصورة الأصلية: " . $files['original'] . "\n";
|
|
echo "- النسخة المصغرة: " . $files['thumbnail'] . "\n";
|
|
|
|
} catch (Exception $e) {
|
|
echo "خطأ: " . $e->getMessage() . "\n";
|
|
}
|