Plugin Directory

Changeset 3449184


Ignore:
Timestamp:
01/29/2026 03:30:27 AM (2 months ago)
Author:
rapls
Message:

Update to version 1.0.9 - Fixed: PDF/X-1:2001 format PDFs now generate correct thumbnails instead of black images

Location:
rapls-pdf-image-creator/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • rapls-pdf-image-creator/trunk/includes/Engine/ImagickEngine.php

    r3430806 r3449184  
    135135            $imagick->readImage($pdfPath . '[' . $page . ']');
    136136
     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
    137145            // Set background color for transparency
    138146            $bgColor = $this->getBgColor($options['bgcolor']);
  • rapls-pdf-image-creator/trunk/includes/Generator.php

    r3430806 r3449184  
    362362
    363363        // 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');
    365365        update_post_meta($attachmentId, '_rapls_pic_source_pdf', $pdfId);
    366366
  • rapls-pdf-image-creator/trunk/includes/MediaLibrary.php

    r3430806 r3449184  
    208208    public function filterAttachmentForJs(array $response, \WP_Post $attachment, $meta): array
    209209    {
     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
    210240        // Only process PDFs
    211241        if ($response['mime'] !== 'application/pdf') {
     
    237267        $thumbnailDir = trailingslashit(dirname($thumbnailFile));
    238268
    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
    241272        $response['width'] = $thumbnailMeta['width'] ?? 0;
    242273        $response['height'] = $thumbnailMeta['height'] ?? 0;
     
    284315    public function filterRestAttachment(\WP_REST_Response $response, \WP_Post $post, \WP_REST_Request $request): \WP_REST_Response
    285316    {
     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
    286343        // Only process PDFs
    287344        $mimeType = get_post_mime_type($post->ID);
     
    316373        $thumbnailDir = trailingslashit(dirname($thumbnailFile));
    317374
    318         // Update source_url to thumbnail
    319         $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
    320377
    321378        // Build media_details from thumbnail
     
    552609
    553610    /**
    554      * Allow PDFs with thumbnails in image selection queries
     611     * Allow PDFs with thumbnails in image selection queries and hide generated thumbnails
    555612     *
    556613     * @param array $query Query arguments
     
    559616    public function allowPdfsInImageSelection(array $query): array
    560617    {
     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
    561639        // Check if this is an image-only query
    562640        if (!isset($query['post_mime_type'])) {
  • rapls-pdf-image-creator/trunk/rapls-pdf-image-creator.php

    r3444486 r3449184  
    1313 * Plugin URI:  https://raplsworks.com/wordpress-rapls-pdf-image-creator/
    1414 * Description: Automatically generate thumbnail images from PDF files uploaded to the Media Library.
    15  * Version:     1.0.7.1
     15 * Version:     1.0.9
    1616 * Author:      Rapls Works
    1717 * Author URI:  https://raplsworks.com
     
    4747
    4848// Plugin constants
    49 define('RAPLS_PIC_VERSION', '1.0.7');
     49define('RAPLS_PIC_VERSION', '1.0.9');
    5050define('RAPLS_PIC_PLUGIN_FILE', __FILE__);
    5151define('RAPLS_PIC_PLUGIN_DIR', plugin_dir_path(__FILE__));
  • rapls-pdf-image-creator/trunk/readme.txt

    r3444486 r3449184  
    66Requires at least: 5.0
    77Tested up to: 6.9
    8 Stable tag: 1.0.7.1
     8Stable tag: 1.0.9
    99Requires PHP: 7.4
    1010License: GPLv2 or later
     
    182182
    183183== 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
    187193* Removed deprecated load_plugin_textdomain() call (auto-loaded since WordPress 4.6)
    188194* Updated Japanese translations to follow WordPress translation style guide
Note: See TracChangeset for help on using the changeset viewer.