Changeset 3449184
- Timestamp:
- 01/29/2026 03:30:27 AM (2 months ago)
- Location:
- rapls-pdf-image-creator/trunk
- Files:
-
- 5 edited
-
includes/Engine/ImagickEngine.php (modified) (1 diff)
-
includes/Generator.php (modified) (1 diff)
-
includes/MediaLibrary.php (modified) (6 diffs)
-
rapls-pdf-image-creator.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
rapls-pdf-image-creator/trunk/includes/Engine/ImagickEngine.php
r3430806 r3449184 135 135 $imagick->readImage($pdfPath . '[' . $page . ']'); 136 136 137 // Handle CMYK colorspace (PDF/X-1:2001 etc.) 138 // Must convert BEFORE flattening to avoid black output 139 $colorspace = $imagick->getImageColorspace(); 140 if ($colorspace === \Imagick::COLORSPACE_CMYK) { 141 // Transform CMYK to sRGB 142 $imagick->transformImageColorspace(\Imagick::COLORSPACE_SRGB); 143 } 144 137 145 // Set background color for transparency 138 146 $bgColor = $this->getBgColor($options['bgcolor']); -
rapls-pdf-image-creator/trunk/includes/Generator.php
r3430806 r3449184 362 362 363 363 // Mark as PDF thumbnail (for filtering in media library) 364 update_post_meta($attachmentId, '_rapls_pic_is_thumbnail', true);364 update_post_meta($attachmentId, '_rapls_pic_is_thumbnail', '1'); 365 365 update_post_meta($attachmentId, '_rapls_pic_source_pdf', $pdfId); 366 366 -
rapls-pdf-image-creator/trunk/includes/MediaLibrary.php
r3430806 r3449184 208 208 public function filterAttachmentForJs(array $response, \WP_Post $attachment, $meta): array 209 209 { 210 // Check if this is a generated thumbnail - show source PDF URL instead 211 $isThumbnail = get_post_meta($attachment->ID, '_rapls_pic_is_thumbnail', true); 212 $sourcePdfId = get_post_meta($attachment->ID, '_rapls_pic_source_pdf', true); 213 214 // Also check by post_parent for older thumbnails without meta 215 if (empty($sourcePdfId) && $attachment->post_parent > 0) { 216 $parentMime = get_post_mime_type($attachment->post_parent); 217 if ($parentMime === 'application/pdf') { 218 $sourcePdfId = $attachment->post_parent; 219 $isThumbnail = true; 220 } 221 } 222 223 if (!empty($isThumbnail) && !empty($sourcePdfId)) { 224 $pdfUrl = wp_get_attachment_url((int) $sourcePdfId); 225 if ($pdfUrl) { 226 // Replace URL with source PDF URL for "File URL" field and "Copy URL" button 227 $response['url'] = $pdfUrl; 228 // Also update link if it exists 229 if (isset($response['link'])) { 230 $response['link'] = get_attachment_link((int) $sourcePdfId); 231 } 232 // Add marker for JavaScript 233 $response['picSourcePdfId'] = (int) $sourcePdfId; 234 $response['picSourcePdfUrl'] = $pdfUrl; 235 $response['picIsThumbnail'] = true; 236 } 237 return $response; 238 } 239 210 240 // Only process PDFs 211 241 if ($response['mime'] !== 'application/pdf') { … … 237 267 $thumbnailDir = trailingslashit(dirname($thumbnailFile)); 238 268 239 // Set main image properties from thumbnail 240 $response['url'] = $thumbnailUrl; 269 // Keep PDF URL for "File URL" field - DO NOT replace with thumbnail URL 270 // $response['url'] stays as the PDF URL 271 // Only set image dimensions from thumbnail for display purposes 241 272 $response['width'] = $thumbnailMeta['width'] ?? 0; 242 273 $response['height'] = $thumbnailMeta['height'] ?? 0; … … 284 315 public function filterRestAttachment(\WP_REST_Response $response, \WP_Post $post, \WP_REST_Request $request): \WP_REST_Response 285 316 { 317 // Check if this is a generated thumbnail - show source PDF URL instead 318 $isThumbnail = get_post_meta($post->ID, '_rapls_pic_is_thumbnail', true); 319 $sourcePdfId = get_post_meta($post->ID, '_rapls_pic_source_pdf', true); 320 321 // Also check by post_parent for older thumbnails without meta 322 if (empty($sourcePdfId) && $post->post_parent > 0) { 323 $parentMime = get_post_mime_type($post->post_parent); 324 if ($parentMime === 'application/pdf') { 325 $sourcePdfId = $post->post_parent; 326 $isThumbnail = true; 327 } 328 } 329 330 if (!empty($isThumbnail) && !empty($sourcePdfId)) { 331 $pdfUrl = wp_get_attachment_url((int) $sourcePdfId); 332 if ($pdfUrl) { 333 $data = $response->get_data(); 334 $data['source_url'] = $pdfUrl; 335 $data['link'] = get_attachment_link((int) $sourcePdfId); 336 $data['rapls_pic_source_pdf_id'] = (int) $sourcePdfId; 337 $data['rapls_pic_source_pdf_url'] = $pdfUrl; 338 $response->set_data($data); 339 } 340 return $response; 341 } 342 286 343 // Only process PDFs 287 344 $mimeType = get_post_mime_type($post->ID); … … 316 373 $thumbnailDir = trailingslashit(dirname($thumbnailFile)); 317 374 318 // Update source_url to thumbnail319 $data['source_url'] = $thumbnailUrl;375 // Keep PDF URL for source_url - DO NOT replace with thumbnail URL 376 // $data['source_url'] stays as the PDF URL 320 377 321 378 // Build media_details from thumbnail … … 552 609 553 610 /** 554 * Allow PDFs with thumbnails in image selection queries 611 * Allow PDFs with thumbnails in image selection queries and hide generated thumbnails 555 612 * 556 613 * @param array $query Query arguments … … 559 616 public function allowPdfsInImageSelection(array $query): array 560 617 { 618 // Hide generated thumbnails from AJAX media queries 619 $hideThumbnails = $this->settings->shouldHideGeneratedImages(); 620 $hideThumbnails = apply_filters('rapls_pdf_image_creator_hide_thumbnails_in_library', $hideThumbnails); 621 622 if ($hideThumbnails) { 623 $metaQuery = isset($query['meta_query']) ? $query['meta_query'] : []; 624 $metaQuery[] = [ 625 'relation' => 'OR', 626 [ 627 'key' => '_rapls_pic_is_thumbnail', 628 'compare' => 'NOT EXISTS', 629 ], 630 [ 631 'key' => '_rapls_pic_is_thumbnail', 632 'value' => '1', 633 'compare' => '!=', 634 ], 635 ]; 636 $query['meta_query'] = $metaQuery; 637 } 638 561 639 // Check if this is an image-only query 562 640 if (!isset($query['post_mime_type'])) { -
rapls-pdf-image-creator/trunk/rapls-pdf-image-creator.php
r3444486 r3449184 13 13 * Plugin URI: https://raplsworks.com/wordpress-rapls-pdf-image-creator/ 14 14 * Description: Automatically generate thumbnail images from PDF files uploaded to the Media Library. 15 * Version: 1.0. 7.115 * Version: 1.0.9 16 16 * Author: Rapls Works 17 17 * Author URI: https://raplsworks.com … … 47 47 48 48 // Plugin constants 49 define('RAPLS_PIC_VERSION', '1.0. 7');49 define('RAPLS_PIC_VERSION', '1.0.9'); 50 50 define('RAPLS_PIC_PLUGIN_FILE', __FILE__); 51 51 define('RAPLS_PIC_PLUGIN_DIR', plugin_dir_path(__FILE__)); -
rapls-pdf-image-creator/trunk/readme.txt
r3444486 r3449184 6 6 Requires at least: 5.0 7 7 Tested up to: 6.9 8 Stable tag: 1.0. 7.18 Stable tag: 1.0.9 9 9 Requires PHP: 7.4 10 10 License: GPLv2 or later … … 182 182 183 183 == Changelog == 184 = 1.0.7.1 = 185 *Change URL 186 = 1.0.7 = 184 = 1.0.9 = 185 * Fixed: PDF/X-1:2001 format PDFs now generate correct thumbnails instead of black images 186 * Added CMYK to sRGB colorspace conversion for print-optimized PDFs 187 188 = 1.0.8 = 189 * Fixed: PDF attachment details now show PDF URL instead of thumbnail URL 190 * Fixed: Generated thumbnails show source PDF URL in attachment details 191 * Fixed: "Copy URL to clipboard" copies PDF URL for both PDF and thumbnail 192 * Fixed: Generated thumbnails properly hidden in AJAX media library queries 187 193 * Removed deprecated load_plugin_textdomain() call (auto-loaded since WordPress 4.6) 188 194 * Updated Japanese translations to follow WordPress translation style guide
Note: See TracChangeset
for help on using the changeset viewer.