Epaper Php Script -
/** * Load image from file */ public function loadImage($path) $extension = strtolower(pathinfo($path, PATHINFO_EXTENSION)); switch($extension) case 'jpg': case 'jpeg': return imagecreatefromjpeg($path); case 'png': return imagecreatefrompng($path); case 'bmp': return imagecreatefrombmp($path); default: throw new Exception("Unsupported image format: $extension");
case 'display/text': if ($method === 'POST') $data = json_decode(file_get_contents('php://input'), true); $display->displayText($data['text'], $data['font_size'] ?? 24); echo json_encode(['success' => true]); break; case 'info': echo json_encode($display->getInfo()); break;
/** * Send display refresh command */ private function sendRefreshCommand() // Execute system command to refresh e-paper exec('echo 1 > /sys/class/graphics/fb0/refresh'); // Alternative: send IOCTL command via Python script exec('python3 /usr/local/bin/epaper_refresh.py'); epaper php script
/** * Get display information */ public function getInfo() return [ 'width' => $this->width, 'height' => $this->height, 'color_mode' => $this->colorMode, 'rotation' => $this->rotation, 'device' => $this->devicePath ];
function handleImageAPI($display) // API image handling logic return ['success' => true]; /** * Load image from file */ public
/** * Convert image to e-paper compatible format */ public function convertForEPaper($image) // Resize image to fit display $resized = imagecreatetruecolor($this->width, $this->height); imagecopyresampled($resized, $image, 0, 0, 0, 0, $this->width, $this->height, imagesx($image), imagesy($image)); // Apply dithering for better e-paper rendering if ($this->colorMode == self::COLOR_BW) imagefilter($resized, IMG_FILTER_GRAYSCALE); // Threshold for black/white for ($x = 0; $x < $this->width; $x++) for ($y = 0; $y < $this->height; $y++) $rgb = imagecolorat($resized, $x, $y); $gray = ($rgb >> 16) & 0xFF; $color = ($gray > 127) ? 255 : 0; imagesetpixel($resized, $x, $y, imagecolorallocate($resized, $color, $color, $color)); return $resized;
// Start session for messages session_start(); case 'png': return imagecreatefrompng($path)
/** * Create a blank image buffer */ public function createBlankImage() $image = imagecreatetruecolor($this->width, $this->height); // Set white background $white = imagecolorallocate($image, 255, 255, 255); imagefill($image, 0, 0, $white); return $image;