• Resolved kolshix

    (@kolshix)


    Your plugin is very cool!
    I have a problem:
    All the thumbnails of the pictures are registered in the database – but the original PNG is not recorded in the database –
    I load more than 200 pictures per day – some of them are deleted – thus it is very difficult to monitor the remaining originals of PNG on hosting

    Can somehow modify the plugin so that the originals PNG are registered in the database to the sizes of the thumbnails?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter kolshix

    (@kolshix)

    [RESOLVED]

    Plugin does not write the original PNG in the database – To fix this, you need

    edit the code in:

    /wp-admin/includes/image.php

    find and add the code in function

    function wp_generate_attachment_metadata( $attachment_id, $file )

    
                if ( ! is_wp_error( $editor ) )
    				$metadata['sizes'] = $editor->multi_resize( $sizes );
    		} else {
    			$metadata['sizes'] = array();
    		}
    
    /* START - kolshix for "PNG to JPG" ---- 
    // add original PNG in databese image "_wp_attachment_metadata"
    // call original image PNG <?php echo wp_get_attachment_image_url( $id, 'png_original' ) ?> 
    // у плагина должна стоять настройка автоматической подмены файлов PNG на JPG 
    // также  должна стоять настройка сохранения оригинала PNG
    // возьмем (адррес + файл) и зменим расширение на PNG 
    // если формат GIF TIF BMP - то они не пройдут проверку расширения - и база данных будет не тронута 
    // если файл JPG то он войдет в правило замены но не пройдет правило наличия файла PNG - которого нет, а значит база будет не тронута 
    // Когда грузите PNG - все будет отлично и он прайдет все правила
    */
    
    $file_png = preg_replace("/\.jpg$/", ".png", $file);
    $results_path_parts = pathinfo($file);
    $results_extension = $results_path_parts['extension'];
    $results_extension = mb_strtolower($results_extension);
    
    if (file_exists( $file_png ) && $results_extension == 'jpg') {
    	 $results = $metadata['file'];
    	 $results = basename($results);  
    	 $results = preg_replace("/\.jpg$/", ".png", $results);
    	 $metadata[sizes][png_original] = Array(
    		"file" => $results,
    		"width" => $metadata['width'],   // ширину вытяну из metadata
    		"height" => $metadata['height'],  // высоту вытяну из metadata
    		"mime-type" => "image/png"
    	 ); 
    }
    /* END - kolshix for "PNG to JPG" ---- */
    
    		// Fetch additional metadata from EXIF/IPTC.
    		$image_meta = wp_read_image_metadata( $file );
    		if ( $image_meta )
    

    Большое спасибо , плагин помог избавится от грамостских страниц с форматом ПНГ и позволил сохранить оригиналы для меня и моих пользователей! А главное Это БЕСПЛАТНО !

    • This reply was modified 7 years, 7 months ago by kolshix.
    Plugin Author kubiq

    (@kubiq)

    NEVER EDIT FILES IN wp-admin OR wp-include FOLDER !!!

    Thread Starter kolshix

    (@kolshix)

    NEVER EDIT FILES IN wp-admin OR wp-include FOLDER !!!

    It was a task to obtain a solution in any way. It was necessary to train on something. After defining the function – selecting rules – all settings are transferred to the function file.

    Since my knowledge of PHP is negligible – I showed where to start and what is being edited – then the user selects his own actions

    // wp_generate_attachment_metadata
    add_action( 'wp_generate_attachment_metadata',array( &$this,'replace_uploaded_image'));

    This is all done based on your plugin
    Having studied its functions, I supplemented it with analogues

    Now I can use the plugins “miniature regeneration” and plugins “image replacement” – These plugins now connect to the settings PNG to JPG

    • This reply was modified 7 years, 7 months ago by kolshix.
    • This reply was modified 7 years, 7 months ago by kolshix.
    • This reply was modified 7 years, 7 months ago by kolshix.
    • This reply was modified 7 years, 7 months ago by kolshix.
    • This reply was modified 7 years, 7 months ago by kolshix.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘no original in DB’ is closed to new replies.