private function saveToJpeg()
 {
     $jpegFile = new pel\PelJpeg($this->filePath);
     $exif = $jpegFile->getExif();
     $tiff = $exif->getTiff();
     $ifd0 = $tiff->getIfd();
     switch ($this->tag) {
         case 'Description':
             $ifd0->addEntry(new pel\PelEntryAscii(pel\PelTag::IMAGE_DESCRIPTION, $this->value));
             break;
         default:
             break;
     }
     $jpegFile->saveFile($this->filePath);
     $this->refreshDatabase();
     print 'save se povedlo';
     header("Refresh:5; url=index.php", true, 303);
 }
 /**
  * Strip orientation from EXIF data for an image at a path.
  *
  * @param $filePath
  *
  * @return bool
  */
 public function stripOrientationFromExifData($filePath)
 {
     if (!ImageHelper::canHaveExifData($filePath)) {
         return null;
     }
     $data = new PelDataWindow(IOHelper::getFileContents($filePath));
     // Is this a valid JPEG?
     if (PelJpeg::isValid($data)) {
         $jpeg = $file = new PelJpeg();
         $jpeg->load($data);
         $exif = $jpeg->getExif();
         if ($exif) {
             $tiff = $exif->getTiff();
             $ifd0 = $tiff->getIfd();
             // Delete the Orientation entry and re-save the file
             $ifd0->offsetUnset(PelTag::ORIENTATION);
             $file->saveFile($filePath);
             return true;
         }
     }
     return false;
 }
 /**
  * Strip orientation from EXIF data for an image at a path.
  *
  * @param $filePath
  *
  * @return bool
  */
 public function stripOrientationFromExifData($filePath)
 {
     if (!ImageHelper::canHaveExifData($filePath)) {
         return null;
     }
     // Quick and dirty, if possible
     if ($this->isImagick() && method_exists('Imagick', 'setImageProperty')) {
         $image = new \Imagick($filePath);
         $image->setImageOrientation(\Imagick::ORIENTATION_UNDEFINED);
         $image->writeImages($filePath, true);
         return true;
     }
     $data = new PelDataWindow(IOHelper::getFileContents($filePath));
     // Is this a valid JPEG?
     if (PelJpeg::isValid($data)) {
         $jpeg = $file = new PelJpeg();
         $jpeg->load($data);
         $exif = $jpeg->getExif();
         if ($exif) {
             $tiff = $exif->getTiff();
             $ifd0 = $tiff->getIfd();
             // Delete the Orientation entry and re-save the file
             $ifd0->offsetUnset(PelTag::ORIENTATION);
             $file->saveFile($filePath);
             return true;
         }
     }
     return false;
 }
Exemple #4
-1
}
/* The input file is now loaded into a PelJpeg object. */
println('Reading file "%s".', $input);
$input_jpeg = new PelJpeg($input);
/*
 * The input image is already loaded, so we can reuse the bytes stored
 * in $input_jpeg when creating the Image resource.
 */
$original = ImageCreateFromString($input_jpeg->getBytes());
$original_w = ImagesX($original);
$original_h = ImagesY($original);
$scaled_w = $original_w * $scale;
$scaled_h = $original_h * $scale;
/* Now create the scaled image. */
$scaled = ImageCreateTrueColor($scaled_w, $scaled_h);
ImageCopyResampled($scaled, $original, 0, 0, 0, 0, $scaled_w, $scaled_h, $original_w, $original_h);
/*
 * We want the raw JPEG data from $scaled. Luckily, one can create a
 * PelJpeg object from an image resource directly:
 */
$output_jpeg = new PelJpeg($scaled);
/* Retrieve the original Exif data in $jpeg (if any). */
$exif = $input_jpeg->getExif();
/* If no Exif data was present, then $exif is null. */
if ($exif != null) {
    $output_jpeg->setExif($exif);
}
/* We can now save the scaled image. */
println('Writing file "%s".', $output);
$output_jpeg->saveFile($output);