Beispiel #1
0
/**
 * Returns the requested EXIF/IPTC tag from the current image
 *
 * If $tags is an array all given tags are tried until a
 * value is found. If no value is found $alt is returned.
 *
 * Which texts are known is defined in the functions _exifTagNames
 * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
 * to the names of the latter one)
 *
 * Only allowed in: detail.php
 *
 * @author Andreas Gohr <*****@*****.**>
 * @param array  $tags tags to try
 * @param string $alt alternative output if no data was found
 * @param null   $src the image src, uses global $SRC if not given
 * @return string
 */
function tpl_img_getTag($tags, $alt = '', $src = null)
{
    // Init Exif Reader
    global $SRC;
    if (is_null($src)) {
        $src = $SRC;
    }
    static $meta = null;
    if (is_null($meta)) {
        $meta = new JpegMeta($src);
    }
    if ($meta === false) {
        return $alt;
    }
    $info = $meta->getField($tags);
    if ($info == false) {
        return $alt;
    }
    return $info;
}
Beispiel #2
0
/**
 * resize or crop images using PHP's libGD support
 *
 * @author Andreas Gohr <*****@*****.**>
 * @author Sebastian Wienecke <*****@*****.**>
 */
function media_resize_imageGD($ext, $from, $from_w, $from_h, $to, $to_w, $to_h, $ofs_x = 0, $ofs_y = 0)
{
    global $conf;
    if ($conf['gdlib'] < 1) {
        return false;
    }
    //no GDlib available or wanted
    // check available memory
    if (!is_mem_available($from_w * $from_h * 4 + $to_w * $to_h * 4)) {
        return false;
    }
    // create an image of the given filetype
    if ($ext == 'jpg' || $ext == 'jpeg') {
        if (!function_exists("imagecreatefromjpeg")) {
            return false;
        }
        $image = @imagecreatefromjpeg($from);
        // rotate the image according to exif orientation tag
        if ($image) {
            $meta = new JpegMeta($from);
            $orientation = $meta->getField("Orientation");
            switch ($orientation) {
                case 3:
                    // rotate 180 degrees clockwise
                    if ($conf['syslog']) {
                        syslog(LOG_WARNING, '[media.php] media_resize_imageGD:orientation: ' . $orientation . ' rotate 180 degrees clockwise');
                    }
                    $image = imagerotate($image, 180, 0);
                    break;
                case 6:
                    // only rotate to vertical if width is larger than height
                    if (intval($from_w) > intval($from_h)) {
                        // rotage image 90 degrees clockwise
                        if ($conf['syslog']) {
                            syslog(LOG_WARNING, '[media.php] media_resize_imageGD:orientation: ' . $orientation . ' rotate 90 degrees clockwise');
                        }
                        $image = imagerotate($image, -90, 0);
                        if ($conf['syslog']) {
                            syslog(LOG_WARNING, '[media.php] media_resize_imageGD: swap width and height as we have just rotated the image vertically');
                        }
                        $from_w_old = $from_w;
                        $to_w_old = $to_w;
                        $from_w = $from_h;
                        $to_w = $to_h;
                        $from_h = $from_w_old;
                        $to_h = $to_w_old;
                    }
                    break;
                case 8:
                    // only rotate to vertical if width is larger than height
                    if (intval($from_w) > intval($from_h)) {
                        if ($conf['syslog']) {
                            syslog(LOG_WARNING, '[media.php] media_resize_imageGD:orientation: ' . $orientation . ' rotate 90 degrees anti-clockwise');
                        }
                        // rotage image 90 degrees anti-clockwise
                        $image = imagerotate($image, 90, 0);
                        if ($conf['syslog']) {
                            syslog(LOG_WARNING, '[media.php] media_resize_imageGD: swap width and height as we have just rotated the image vertically');
                        }
                        $from_w_old = $from_w;
                        $to_w_old = $to_w;
                        $from_w = $from_h;
                        $to_w = $to_h;
                        $from_h = $from_w_old;
                        $to_h = $to_w_old;
                    }
                    break;
            }
        }
    } elseif ($ext == 'png') {
        if (!function_exists("imagecreatefrompng")) {
            return false;
        }
        $image = @imagecreatefrompng($from);
    } elseif ($ext == 'gif') {
        if (!function_exists("imagecreatefromgif")) {
            return false;
        }
        $image = @imagecreatefromgif($from);
    }
    if (!$image) {
        return false;
    }
    if ($conf['gdlib'] > 1 && function_exists("imagecreatetruecolor") && $ext != 'gif') {
        $newimg = @imagecreatetruecolor($to_w, $to_h);
    }
    if (!$newimg) {
        $newimg = @imagecreate($to_w, $to_h);
    }
    if (!$newimg) {
        imagedestroy($image);
        return false;
    }
    //keep png alpha channel if possible
    if ($ext == 'png' && $conf['gdlib'] > 1 && function_exists('imagesavealpha')) {
        imagealphablending($newimg, false);
        imagesavealpha($newimg, true);
    }
    //keep gif transparent color if possible
    if ($ext == 'gif' && function_exists('imagefill') && function_exists('imagecolorallocate')) {
        if (function_exists('imagecolorsforindex') && function_exists('imagecolortransparent')) {
            $transcolorindex = @imagecolortransparent($image);
            if ($transcolorindex >= 0) {
                //transparent color exists
                $transcolor = @imagecolorsforindex($image, $transcolorindex);
                $transcolorindex = @imagecolorallocate($newimg, $transcolor['red'], $transcolor['green'], $transcolor['blue']);
                @imagefill($newimg, 0, 0, $transcolorindex);
                @imagecolortransparent($newimg, $transcolorindex);
            } else {
                //filling with white
                $whitecolorindex = @imagecolorallocate($newimg, 255, 255, 255);
                @imagefill($newimg, 0, 0, $whitecolorindex);
            }
        } else {
            //filling with white
            $whitecolorindex = @imagecolorallocate($newimg, 255, 255, 255);
            @imagefill($newimg, 0, 0, $whitecolorindex);
        }
    }
    //try resampling first
    if (function_exists("imagecopyresampled")) {
        if (!@imagecopyresampled($newimg, $image, 0, 0, $ofs_x, $ofs_y, $to_w, $to_h, $from_w, $from_h)) {
            imagecopyresized($newimg, $image, 0, 0, $ofs_x, $ofs_y, $to_w, $to_h, $from_w, $from_h);
        }
    } else {
        imagecopyresized($newimg, $image, 0, 0, $ofs_x, $ofs_y, $to_w, $to_h, $from_w, $from_h);
    }
    $okay = false;
    if ($ext == 'jpg' || $ext == 'jpeg') {
        if (!function_exists('imagejpeg')) {
            $okay = false;
        } else {
            $okay = imagejpeg($newimg, $to, $conf['jpg_quality']);
        }
    } elseif ($ext == 'png') {
        if (!function_exists('imagepng')) {
            $okay = false;
        } else {
            // add compress png image if png_qulaity is set
            if ($conf['png_quality']) {
                $okay = imagepng($newimg, $to, $conf['png_quality']);
            } else {
                $okay = imagepng($newimg, $to);
            }
        }
    } elseif ($ext == 'gif') {
        if (!function_exists('imagegif')) {
            $okay = false;
        } else {
            $okay = imagegif($newimg, $to);
        }
    }
    // destroy GD image ressources
    if ($image) {
        imagedestroy($image);
    }
    if ($newimg) {
        imagedestroy($newimg);
    }
    return $okay;
}
Beispiel #3
0
/**
 * Returns the requested EXIF/IPTC tag from the image meta
 *
 * @author Kate Arzamastseva <*****@*****.**>
 * @param array $tags
 * @param JpegMeta $meta
 * @param string $alt
 * @return string
 */
function media_getTag($tags, $meta, $alt = '')
{
    if ($meta === false) {
        return $alt;
    }
    $info = $meta->getField($tags);
    if ($info == false) {
        return $alt;
    }
    return $info;
}
 /**
  * Defines how a thumbnail should look like
  */
 function _image($data, &$renderer = null, $mode = 'xhtml')
 {
     global $ID;
     if (is_null($renderer) || empty($data['src'])) {
         return false;
     }
     if (!is_array($data['params'])) {
         $data['params'] = array();
     }
     //prepare link attributes
     // can use reflected images
     $reflect = array();
     if ($reflection = plugin_load('syntax', 'reflect')) {
         $reflect = array('reflect' => $this->getConf('reflect') ? 1 : 0, 'bgc' => $this->getConf('reflectBackground'));
     }
     // Start Section
     if ($mode != 'metadata') {
         $renderer->doc .= '<div class="imageflow_image">' . NL;
     }
     // Display
     $data['params']['tok'] = media_get_token($data['src'], $data['params']['w'], $data['params']['h']);
     $href = ml($data['src'], array_merge($data['params'], $reflect), true, '&');
     if ($mode != 'metadata' && empty($data['alternate_desc'])) {
         $renderer->doc .= '<img src="' . $href . '" alt="" class="imageflow__noscript__image media"/>';
     }
     // Set Data
     $fn = mediaFN($data['src']);
     $data['src'] = ml($data['src']);
     $data['params'] = array_merge($data['params'], $reflect);
     // Remove everything except the params.
     $data['desc'] = trim($data['desc']);
     $data['title'] = trim($data['title']);
     if (empty($data['desc']) && ($meta = new JpegMeta($fn))) {
         $data['title'] = $meta->getField('Iptc.Headline');
         $data['desc'] = $meta->getField('Iptc.Caption');
     }
     if ($mode != 'metadata') {
         if (!empty($data['alternate_desc'])) {
             $renderer->doc .= $data['alternate_desc'];
         } else {
             $renderer->doc .= '<div class="imageflow_caption">' . NL;
             if (!empty($data['title'])) {
                 $renderer->doc .= "<h3 class=\"imageflow__title\">{$data['title']}</h3>" . NL;
             }
             if (!empty($data['desc'])) {
                 $renderer->doc .= "<p class=\"imageflow__text\">{$data['desc']}</p>" . NL;
             }
             // End Caption
             $renderer->doc .= '</div>' . NL;
         }
         // End Section
         $renderer->doc .= '<div class="clearer"></div>' . NL . '</div>' . NL;
     } else {
         // Add Metadata
         unset($data['alternate_desc']);
         if (!$data['isImage'] && !empty($data['linkto'])) {
             $data['id'] = $data['linkto'];
             unset($data['linkto']);
         }
         $renderer->meta['relation']['imageflow'][$this->sectionID[sizeof($this->sectionID) - 1]][] = $data;
     }
     return $data;
 }