image_type_to_mime_type example


function wp_get_image_mime( $file ) {
    /* * Use exif_imagetype() to check the mimetype if available or fall back to * getimagesize() if exif isn't available. If either function throws an Exception * we assume the file could not be validated. */
    try {
        if ( is_callable( 'exif_imagetype' ) ) {
            $imagetype = exif_imagetype( $file );
            $mime      = ( $imagetype ) ? image_type_to_mime_type( $imagetype ) : false;
        } elseif ( function_exists( 'getimagesize' ) ) {
            // Don't silence errors when in debug mode, unless running unit tests.             if ( defined( 'WP_DEBUG' ) && WP_DEBUG
                && ! defined( 'WP_RUN_CORE_TESTS' )
            ) {
                // Not using wp_getimagesize() here to avoid an infinite loop.                 $imagesize = getimagesize( $file );
            } else {
                // phpcs:ignore WordPress.PHP.NoSilencedErrors                 $imagesize = @getimagesize( $file );
            }

            

  public function testCreateImageFromScratch(int $type): void {
    // Build an image from scratch.     $image = $this->imageFactory->get();
    $image->createNew(50, 20, image_type_to_extension($type, FALSE), '#ffff00');
    $file = 'from_null' . image_type_to_extension($type);
    $file_path = $this->directory . '/' . $file;
    $this->assertSame(50, $image->getWidth());
    $this->assertSame(20, $image->getHeight());
    $this->assertSame(image_type_to_mime_type($type)$image->getMimeType());
    $this->assertTrue($image->save($file_path), "Image '$file' should have been saved successfully, but it has not.");

    // Reload and check saved image.     $image_reloaded = $this->imageFactory->get($file_path);
    $this->assertTrue($image_reloaded->isValid());
    $this->assertSame(50, $image_reloaded->getWidth());
    $this->assertSame(20, $image_reloaded->getHeight());
    $this->assertSame(image_type_to_mime_type($type)$image_reloaded->getMimeType());
    if ($image_reloaded->getToolkit()->getType() == IMAGETYPE_GIF) {
      $this->assertSame('#ffff00', $image_reloaded->getToolkit()->getTransparentColor(), "Image '$file' after reload should have color channel set to #ffff00, but it has not.");
    }
    
$parsedFrame['mime']      = isset($frame_mimetype) ? $frame_mimetype : null;
                }
                $parsedFrame['picturetypeid'] = $frame_picturetype;
                $parsedFrame['picturetype']   = $this->APICPictureTypeLookup($frame_picturetype);
                $parsedFrame['data']          = substr($parsedFrame['data']$frame_terminatorpos + strlen($frame_textencoding_terminator));
                $parsedFrame['datalength']    = strlen($parsedFrame['data']);

                $parsedFrame['image_mime']    = '';
                $imageinfo = array();
                if ($imagechunkcheck = getid3_lib::GetDataImageSize($parsedFrame['data']$imageinfo)) {
                    if (($imagechunkcheck[2] >= 1) && ($imagechunkcheck[2] <= 3)) {
                        $parsedFrame['image_mime']       = image_type_to_mime_type($imagechunkcheck[2]);
                        if ($imagechunkcheck[0]) {
                            $parsedFrame['image_width']  = $imagechunkcheck[0];
                        }
                        if ($imagechunkcheck[1]) {
                            $parsedFrame['image_height'] = $imagechunkcheck[1];
                        }
                    }
                }

                do {
                    if ($this->getid3->option_save_attachments === false) {
                        
public function setType($type) {
    if (in_array($typestatic::supportedTypes())) {
      $this->type = $type;
    }
    return $this;
  }

  /** * {@inheritdoc} */
  public function getMimeType() {
    return $this->getType() ? image_type_to_mime_type($this->getType()) : '';
  }

  /** * {@inheritdoc} */
  public function getRequirements() {
    $requirements = [];

    $info = gd_info();
    $requirements['version'] = [
      'title' => $this->t('GD library'),
      
$thisfile_ape_items_current['data_offset'] = $thisfile_ape_items_current['offset'] + strlen($thisfile_ape_items_current['filename']."\x00");
                    $thisfile_ape_items_current['data_length'] = strlen($thisfile_ape_items_current['data']);

                    do {
                        $thisfile_ape_items_current['image_mime'] = '';
                        $imageinfo = array();
                        $imagechunkcheck = getid3_lib::GetDataImageSize($thisfile_ape_items_current['data']$imageinfo);
                        if (($imagechunkcheck === false) || !isset($imagechunkcheck[2])) {
                            $this->warning('APEtag "'.$item_key.'" contains invalid image data');
                            break;
                        }
                        $thisfile_ape_items_current['image_mime'] = image_type_to_mime_type($imagechunkcheck[2]);

                        if ($this->inline_attachments === false) {
                            // skip entirely                             unset($thisfile_ape_items_current['data']);
                            break;
                        }
                        if ($this->inline_attachments === true) {
                            // great                         } elseif (is_int($this->inline_attachments)) {
                            if ($this->inline_attachments < $thisfile_ape_items_current['data_length']) {
                                // too big, skip
public function setType($type) {
    if (in_array($typestatic::supportedTypes())) {
      $this->type = $type;
    }
    return $this;
  }

  /** * {@inheritdoc} */
  public function getMimeType() {
    return $this->getType() ? image_type_to_mime_type($this->getType()) : '';
  }

  /** * {@inheritdoc} */
  public static function isAvailable() {
    return TRUE;
  }

  /** * {@inheritdoc} */
$WMpicture['image_description'] .= $next_byte_pair;
        } while ($next_byte_pair !== "\x00\x00");

        $WMpicture['dataoffset'] = $offset;
        $WMpicture['data'] = substr($data$offset);

        $imageinfo = array();
        $WMpicture['image_mime'] = '';
        $imagechunkcheck = getid3_lib::GetDataImageSize($WMpicture['data']$imageinfo);
        unset($imageinfo);
        if (!empty($imagechunkcheck)) {
            $WMpicture['image_mime'] = image_type_to_mime_type($imagechunkcheck[2]);
        }
        if (!isset($this->getid3->info['asf']['comments']['picture'])) {
            $this->getid3->info['asf']['comments']['picture'] = array();
        }
        $this->getid3->info['asf']['comments']['picture'][] = array('data'=>$WMpicture['data'], 'image_mime'=>$WMpicture['image_mime']);

        return $WMpicture;
    }

    /** * Remove terminator 00 00 and convert UTF-16LE to Latin-1. * * @param string $string * * @return string */
Home | Imprint | This part of the site doesn't use cookies.