| | |
| | | <?php |
| | | namespace JVBase\managers; |
| | | |
| | | use JVBase\managers\UploadManager; |
| | | use WP_Error; |
| | | use Imagick; |
| | | use ImagickPixel; |
| | |
| | | /** |
| | | * Generate the artist card |
| | | */ |
| | | /** |
| | | * @return array |
| | | */ |
| | | /** |
| | | * @return array |
| | | * @throws Exception |
| | | * @throws Exception |
| | | */ |
| | | public function generate():array |
| | | { |
| | | // Generate appropriate filename |
| | |
| | | ]; |
| | | } |
| | | |
| | | /** |
| | | * Create WordPress attachment from generated image |
| | | * @param string $file_path |
| | | * |
| | | * @return int|WP_Error |
| | | */ |
| | | /** |
| | | * Create WordPress attachment from generated image |
| | | * @param string $file_path |
| | | * |
| | | * @return int|WP_Error |
| | | * @throws Exception |
| | | * @throws Exception |
| | | */ |
| | | protected function createAttachment(string $file_path):int|WP_Error |
| | | { |
| | | // Get upload directory based on user/content structure |
| | |
| | | $artist_name = $this->data['display_name']; |
| | | $city = $this->data['city']; |
| | | |
| | | switch ($this->type) { |
| | | case 'shop': |
| | | $title = 'Featured Shop Image'; |
| | | break; |
| | | default: |
| | | $title = 'Featured Artist Image'; |
| | | } |
| | | $title = match ($this->type) { |
| | | 'shop' => 'Featured Shop Image', |
| | | default => 'Featured Artist Image', |
| | | }; |
| | | |
| | | $attachment = [ |
| | | 'post_mime_type' => 'image/webp', |
| | |
| | | require_once(ABSPATH . 'wp-admin/includes/media.php'); |
| | | |
| | | |
| | | switch ($this->type) { |
| | | case 'shop': |
| | | $type = 'Tattoo Studio'; |
| | | break; |
| | | default: |
| | | $type = $this->data['type']; |
| | | break; |
| | | } |
| | | $type = match ($this->type) { |
| | | 'shop' => 'Tattoo Studio', |
| | | default => $this->data['type'], |
| | | }; |
| | | // Set alt text |
| | | $alt_text = sprintf( |
| | | 'Featured image for %s - %sin %s', |
| | |
| | | protected function generateFilename():void |
| | | { |
| | | if ($this->fileManager) { |
| | | switch ($this->type) { |
| | | case 'shop': |
| | | $title = 'tattoo-shop'; |
| | | break; |
| | | default: |
| | | $title = 'artist'; |
| | | break; |
| | | } |
| | | $title = match ($this->type) { |
| | | 'shop' => 'tattoo-shop', |
| | | default => 'artist', |
| | | }; |
| | | // Use FileUploadManager to generate a filename |
| | | |
| | | $user_data = get_userdata($this->data['user_id']); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Create gradient background with Imagick |
| | | * @param Imagick $canvas |
| | | * @param string $color Center color |
| | | * @return void |
| | | */ |
| | | protected function createGradientBackgroundImagick(Imagick &$canvas, string $color): void |
| | | /** |
| | | * Create gradient background with Imagick |
| | | * @param Imagick $canvas |
| | | * @param string $color Center color |
| | | * @return void |
| | | * @throws ImagickException |
| | | * @throws ImagickException |
| | | */ |
| | | protected function createGradientBackgroundImagick(Imagick $canvas, string $color): void |
| | | { |
| | | $width = $canvas->getImageWidth(); |
| | | $height = $canvas->getImageHeight(); |
| | |
| | | * @param string $color Center color |
| | | * @return void |
| | | */ |
| | | protected function createGradientBackgroundGD(GdImage &$canvas, string $color):void |
| | | protected function createGradientBackgroundGD(GdImage $canvas, string $color):void |
| | | { |
| | | $width = imagesx($canvas); |
| | | $height = imagesy($canvas); |
| | |
| | | $imageInfo = getimagesize($imagePath); |
| | | |
| | | // Create image from source based on file type |
| | | switch ($imageInfo[2]) { |
| | | case IMAGETYPE_JPEG: |
| | | $sourceImage = imagecreatefromjpeg($imagePath); |
| | | break; |
| | | case IMAGETYPE_PNG: |
| | | $sourceImage = imagecreatefrompng($imagePath); |
| | | break; |
| | | case IMAGETYPE_GIF: |
| | | $sourceImage = imagecreatefromgif($imagePath); |
| | | break; |
| | | case IMAGETYPE_WEBP: |
| | | $sourceImage = imagecreatefromwebp($imagePath); |
| | | break; |
| | | default: |
| | | throw new Exception("Unsupported image type"); |
| | | } |
| | | $sourceImage = match ($imageInfo[2]) { |
| | | IMAGETYPE_JPEG => imagecreatefromjpeg($imagePath), |
| | | IMAGETYPE_PNG => imagecreatefrompng($imagePath), |
| | | IMAGETYPE_GIF => imagecreatefromgif($imagePath), |
| | | IMAGETYPE_WEBP => imagecreatefromwebp($imagePath), |
| | | default => throw new Exception("Unsupported image type"), |
| | | }; |
| | | |
| | | // Calculate dimensions while maintaining aspect ratio |
| | | $sourceWidth = imagesx($sourceImage); |