当前位置: 首页>>代码示例>>PHP>>正文


PHP PelJpeg::saveFile方法代码示例

本文整理汇总了PHP中PelJpeg::saveFile方法的典型用法代码示例。如果您正苦于以下问题:PHP PelJpeg::saveFile方法的具体用法?PHP PelJpeg::saveFile怎么用?PHP PelJpeg::saveFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PelJpeg的用法示例。


在下文中一共展示了PelJpeg::saveFile方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testWriteRead

 function testWriteRead()
 {
     Pel::setStrictParsing(true);
     $ifd = new PelIfd(PelIfd::IFD0);
     $this->assertTrue($ifd->isLastIfd());
     foreach ($this->entries as $entry) {
         $ifd->addEntry($entry);
     }
     $tiff = new PelTiff();
     $this->assertNull($tiff->getIfd());
     $tiff->setIfd($ifd);
     $this->assertNotNull($tiff->getIfd());
     $exif = new PelExif();
     $this->assertNull($exif->getTiff());
     $exif->setTiff($tiff);
     $this->assertNotNull($exif->getTiff());
     $jpeg = new PelJpeg(dirname(__FILE__) . '/no-exif.jpg');
     $this->assertNull($jpeg->getExif());
     $jpeg->setExif($exif);
     $this->assertNotNull($jpeg->getExif());
     $jpeg->saveFile('test-output.jpg');
     $this->assertTrue(file_exists('test-output.jpg'));
     $this->assertTrue(filesize('test-output.jpg') > 0);
     /* Now read the file and see if the entries are still there. */
     $jpeg = new PelJpeg('test-output.jpg');
     $exif = $jpeg->getExif();
     $this->assertIsA($exif, 'PelExif');
     $tiff = $exif->getTiff();
     $this->assertIsA($tiff, 'PelTiff');
     $ifd = $tiff->getIfd();
     $this->assertIsA($ifd, 'PelIfd');
     $this->assertEqual($ifd->getType(), PelIfd::IFD0);
     $this->assertTrue($ifd->isLastIfd());
     foreach ($this->entries as $entry) {
         $this->assertEqual($ifd->getEntry($entry->getTag())->getValue(), $entry->getValue());
     }
     unlink('test-output.jpg');
 }
开发者ID:ni-c,项目名称:pel,代码行数:38,代码来源:read-write.php

示例2: stripOrientationFromExifData

 /**
  * 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;
     } else {
         return false;
     }
 }
开发者ID:harish94,项目名称:Craft-Release,代码行数:30,代码来源:ImagesService.php

示例3: _addExif

 private function _addExif($filename)
 {
     //if ($_SERVER['SERVER_NAME'] == 'test.psychomorph') return true;
     try {
         $jpeg = new PelJpeg($filename);
         if (!($exif = $jpeg->getExif())) {
             // Create and add empty Exif data to the image (this throws away any old Exif data in the image).
             $exif = new PelExif();
             $jpeg->setExif($exif);
         }
         if (!($tiff = $exif->getTiff())) {
             // Create and add TIFF data to the Exif data (Exif data is actually stored in a TIFF format).
             $tiff = new PelTiff();
             $exif->setTiff($tiff);
         }
         if (!($ifd0 = $tiff->getIfd())) {
             // Create first Image File Directory and associate it with the TIFF data.
             $ifd0 = new PelIfd(PelIfd::IFD0);
             $tiff->setIfd($ifd0);
         }
         if (!($exif_ifd = $ifd0->getSubIfd(PelIfd::EXIF))) {
             // Create exif Image File Directory and associate it with the TIFF data.
             $exif_ifd = new PelIfd(PelIfd::EXIF);
             $ifd0->addSubIfd($exif_ifd);
         }
         if (!($ifd1 = $ifd0->getNextIfd())) {
             // thumbnail does not exist
             $ifd1 = new PelIfd(1);
             $ifd0->setNextIfd($ifd1);
             //$original = ImageCreateFromString($jpeg->getBytes()); # create image resource of original
             //$thumb = makeThumb($original);
             $thumb = $this->_makeThumb($this->getImage());
             // start writing output to buffer
             ob_start();
             // outputs thumb resource contents to buffer
             ImageJpeg($thumb);
             // create PelDataWindow from buffer thumb contents (and end output to buffer)
             $window = new PelDataWindow(ob_get_clean());
             if ($window) {
                 $ifd1->setThumbnail($window);
                 # set window data as thumbnail in ifd1
             }
             //imagedestroy($original);
             imagedestroy($thumb);
         }
         $exifdata = array(PelTag::IMAGE_DESCRIPTION => $this->getDescription(), PelTag::COPYRIGHT => "webmorph.org: " . $_SESSION['user_id'] . ': IMG_ID: ', PelTag::USER_COMMENT => $this->_embeddedTem);
         foreach ($exifdata as $PelTag => $val) {
             if ($PelTag == PelTag::USER_COMMENT) {
                 if (!($entry = $exif_ifd->getEntry($PelTag))) {
                     $exif_ifd->addEntry(new PelEntryUserComment($val));
                 } else {
                     $entry->setValue($val);
                 }
             } else {
                 if (!($entry = $ifd0->getEntry($PelTag))) {
                     $ifd0->addEntry(new PelEntryAscii($PelTag, $val));
                 } else {
                     $entry->setValue($val);
                 }
             }
         }
         $jpeg->saveFile($filename);
         return true;
     } catch (Exception $e) {
         // Handle exception
         echo $e;
     }
 }
开发者ID:debruine,项目名称:webmorph,代码行数:68,代码来源:psychomorph.image.class.php

示例4: resize


//.........这里部分代码省略.........
          */
         if ($isOriginalSize && $params->get('use_sharpening_for_originalsize', 1) == 0) {
             $im_output = $im_original;
         } else {
             $im_output = imagecreatetruecolor($width, $height);
             $resize_faktor = $orig_height / $height;
             $new_height = $height;
             $new_width = $orig_width / $resize_faktor;
             if ($new_width < $width) {
                 $resize_faktor = $orig_width / $width;
                 $new_width = $width;
                 $new_height = $orig_height / $resize_faktor;
             }
             imagecopyresampled($im_output, $im_original, $width / 2 - $new_width / 2, $height / 2 - $new_height / 2, 0, 0, $new_width, $new_height, $orig_width, $orig_height);
             $use_sharpening = $params->get('use_sharpening', 1);
             if ($use_sharpening == 1) {
                 // configure the sharpening
                 $stringSharpenMatrix = $params->get('image_sharpenMatrix', '[[-1,-1,-1],[-1,16,-1],[-1,-1,-1]]');
                 $sharpenMatrix = json_decode($stringSharpenMatrix);
                 if (null == $sharpenMatrix || count($sharpenMatrix) != 3) {
                     $sharpenMatrix = array(array(-1, -1, -1), array(-1, 16, -1), array(-1, -1, -1));
                 }
                 $divisor = array_sum(array_map('array_sum', $sharpenMatrix));
                 $offset = 0;
                 if (function_exists('imageconvolution')) {
                     if (version_compare(phpversion(), '5.5.9', '=')) {
                         $this->imageconvolution($im_output, $sharpenMatrix, $divisor, $offset);
                     } else {
                         imageconvolution($im_output, $sharpenMatrix, $divisor, $offset);
                     }
                 }
             }
         }
         /**
          * @var EventgalleryLibraryManagerFolder $folderMgr
          * @var EventgalleryLibraryFolder $folder
          */
         $folderMgr = EventgalleryLibraryManagerFolder::getInstance();
         $folder = $folderMgr->getFolder($folder);
         $watermark = $folder->getWatermark();
         // load default watermark
         if (null == $watermark || !$watermark->isPublished()) {
             /**
              * @var EventgalleryLibraryManagerWatermark $watermarkMgr
              * @var EventgalleryLibraryWatermark $watermark
              */
             $watermarkMgr = EventgalleryLibraryManagerWatermark::getInstance();
             $watermark = $watermarkMgr->getDefaultWatermark();
         }
         if (null != $watermark && $watermark->isPublished()) {
             $watermark->addWatermark($im_output);
         }
         $image_quality = $params->get('image_quality', 85);
         if ($input_jpeg != null) {
             Pel::setJPEGQuality($image_quality);
             /* We want the raw JPEG data from $scaled. Luckily, one can create a
              * PelJpeg object from an image resource directly: */
             $output_jpeg = new PelJpeg($im_output);
             /* If no Exif data was present, then $exif is null. */
             if ($exif != null) {
                 $output_jpeg->setExif($exif);
             }
             /* We can now save the scaled image. */
             $writeSuccess = true;
             $output_jpeg->saveFile($image_thumb_file);
         } else {
             $writeSuccess = imagejpeg($im_output, $image_thumb_file, $image_quality);
             if (!$writeSuccess) {
                 die("Unable to write to file {$image_thumb_file}");
             }
         }
         if (!$writeSuccess) {
             die("Unable to write to file {$image_thumb_file}");
         }
         $time = time() + 315360000;
         touch($image_thumb_file, $time);
         // add the ICC profile
         try {
             $o = new JPEG_ICC();
             $o->LoadFromJPEG($image_file);
             $o->SaveToJPEG($image_thumb_file);
         } catch (Exception $e) {
         }
     }
     $mime = ($mime = getimagesize($image_thumb_file)) ? $mime['mime'] : $mime;
     $size = filesize($image_thumb_file);
     $fp = fopen($image_thumb_file, "rb");
     if (!($mime && $size && $fp)) {
         // Error.
         return;
     }
     if (!$debug) {
         header("Content-Type: " . $mime);
         header("Content-Length: " . $size);
         header("Last-Modified: {$last_modified}");
     }
     fpassthru($fp);
     die;
     //$app->close();
 }
开发者ID:sansandeep143,项目名称:av,代码行数:101,代码来源:Resizeimage.php

示例5: println

    println('  input   the input filename, a JPEG image.');
    println('  output  filename for saving the changed image.');
    println('  scale   scale factor, say 0.5 to resize to half the ' . 'original size.');
    exit(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);
开发者ID:ni-c,项目名称:pel,代码行数:30,代码来源:resize.php

示例6: addExif

function addExif($filename, $exifdata)
{
    try {
        $jpeg = new PelJpeg($filename);
        if (!($exif = $jpeg->getExif())) {
            // Create and add empty Exif data to the image (this throws away any old Exif data in the image).
            $exif = new PelExif();
            $jpeg->setExif($exif);
        }
        if (!($tiff = $exif->getTiff())) {
            // Create and add TIFF data to the Exif data (Exif data is actually stored in a TIFF format).
            $tiff = new PelTiff();
            $exif->setTiff($tiff);
        }
        if (!($ifd0 = $tiff->getIfd())) {
            // Create first Image File Directory and associate it with the TIFF data.
            $ifd0 = new PelIfd(PelIfd::IFD0);
            $tiff->setIfd($ifd0);
        }
        if (!($exif_ifd = $ifd0->getSubIfd(PelIfd::EXIF))) {
            // Create first Image File Directory and associate it with the TIFF data.
            $exif_ifd = new PelIfd(PelIfd::EXIF);
            $ifd0->addSubIfd($exif_ifd);
        }
        if (!($ifd1 = $ifd0->getNextIfd())) {
            // thumbnail does not exist
            $ifd1 = new PelIfd(1);
            $ifd0->setNextIfd($ifd1);
            $original = ImageCreateFromString($jpeg->getBytes());
            # create image resource of original
            $thumb = makeThumb($original);
            // start writing output to buffer
            ob_start();
            // outputs thumb resource contents to buffer
            ImageJpeg($thumb);
            // create PelDataWindow from buffer thumb contents (and end output to buffer)
            $window = new PelDataWindow(ob_get_clean());
            if ($window) {
                $ifd1->setThumbnail($window);
                # set window data as thumbnail in ifd1
            }
            imagedestroy($original);
            imagedestroy($thumb);
        }
        foreach ($exifdata as $PelTag => $val) {
            if ($PelTag == PelTag::USER_COMMENT) {
                if (!($entry = $exif_ifd->getEntry($PelTag))) {
                    $exif_ifd->addEntry(new PelEntryUserComment($val));
                } else {
                    $entry->setValue($val);
                }
            } else {
                if (!($entry = $ifd0->getEntry($PelTag))) {
                    $ifd0->addEntry(new PelEntryAscii($PelTag, $val));
                } else {
                    $entry->setValue($val);
                }
            }
        }
        $jpeg->saveFile($filename);
        return true;
    } catch (Exception $e) {
        // Handle exception
        echo $e;
    }
}
开发者ID:debruine,项目名称:webmorph,代码行数:66,代码来源:fileSave.php

示例7: saveEdit

 function saveEdit()
 {
     // check for image editor access
     if (!$this->checkAccess('image_editor', 1)) {
         JError::raiseError(403, 'RESTRICTED ACCESS');
     }
     $editor = $this->getImageEditor();
     $browser = $this->getBrowser();
     $args = func_get_args();
     // file src
     $file = array_shift($args);
     // check file
     WFUtility::checkPath($file);
     // file name
     $name = array_shift($args);
     // check name
     WFUtility::checkPath($name);
     // check for extension in destination name
     if (preg_match('#\\.(php|php(3|4|5)|phtml|pl|py|jsp|asp|htm|html|shtml|sh|cgi)\\b#i', $name)) {
         JError::raiseError(403, 'INVALID FILE NAME');
     }
     // edit data
     $props = array_shift($args);
     // exif data
     $exif = null;
     $data = JRequest::getVar('data', '', 'POST', 'STRING', JREQUEST_ALLOWRAW);
     if (preg_match('#data:image\\/(jpeg|jpg|png|bmp);base64#', $data)) {
         // replace spaces
         $data = str_replace(' ', '+', $data);
         // remove header
         $data = substr($data, strpos($data, ",") + 1);
         // decode data
         $data = base64_decode($data);
         $src = WFUtility::makePath(JPATH_SITE, $file);
         $dest = dirname($src) . DS . basename($name);
         // get exif data from orignal file
         if (preg_match('#\\.jp(eg|g)$#i', basename($file)) && basename($file) == basename($dest)) {
             // load exif classes
             require_once dirname(__FILE__) . DS . 'pel' . DS . 'PelJpeg.php';
             $jpeg = new PelJpeg($src);
             $exif = $jpeg->getExif();
         }
         if (!JFile::write($dest, $data)) {
             $browser->setResult(WFText::_('WF_IMGMANAGER_EXT_ERROR'), 'error');
         } else {
             $browser->setResult(basename($dest), 'files');
             if ($exif && basename($file) == basename($dest)) {
                 $pel = new PelDataWindow($data);
                 if (PelJpeg::isValid($pel)) {
                     $jpeg = new PelJpeg();
                     $jpeg->load($pel);
                     /*$dim = @getimagesize($dest);
                     		
                     					if ($dim) {
                     					$tiff 	= $exif->getTiff();
                     					$ifd0 	= $tiff->getIfd();
                     		
                     					$width 	= $ifd0->getEntry(PelTag::IMAGE_WIDTH);
                     					$height	= $ifd0->getEntry(PelTag::IMAGE_LENGTH);
                     		
                     					$width->setValue($dim[0]);
                     					$height->setValue($dim[1]);
                     					}*/
                     $jpeg->setExif($exif);
                     $jpeg->saveFile($dest);
                 }
             }
         }
     } else {
         $browser->setResult(WFText::_('WF_IMGMANAGER_EXT_ERROR'), 'error');
     }
     return $browser->getResult();
 }
开发者ID:srbsnkr,项目名称:sellingonlinemadesimple,代码行数:73,代码来源:imgmanager.php

示例8: dirname

 /**
  * @param     $from_file
  * @param     $to_file
  */
 function copy_exif($from_file, $to_file)
 {
     $size = @getimagesize($to_file);
     if ($size) {
         require_once dirname(__FILE__) . '/pel/autoload.php';
         try {
             Pel::setJPEGQuality(100);
             /*
              * We want the raw JPEG data from $scaled. Luckily, one can create a
              * PelJpeg object from an image resource directly:
              */
             $input_jpeg = new PelJpeg($from_file);
             /* Retrieve the original Exif data in $jpeg (if any). */
             $input_exif = $input_jpeg->getExif();
             /* If no Exif data was present, then $input_exif is null. */
             if ($input_exif != null) {
                 $input_tiff = $input_exif->getTiff();
                 if ($input_tiff == null) {
                     return;
                 }
                 $input_ifd0 = $input_tiff->getIfd();
                 if ($input_ifd0 == null) {
                     return;
                 }
                 $input_exif_ifd = $input_ifd0->getSubIfd(PelIfd::EXIF);
                 $input_inter_ifd = $input_ifd0->getSubIfd(PelIfd::INTEROPERABILITY);
                 $orientation = $input_ifd0->getEntry(PelTag::ORIENTATION);
                 if ($orientation != null) {
                     $orientation->setValue(1);
                 }
                 if (!empty($input_ifd0)) {
                     /*$x_resolution = $input_ifd0->getEntry( PelTag::X_RESOLUTION );
                       $y_resolution = $input_ifd0->getEntry( PelTag::Y_RESOLUTION );
                       if ( $x_resolution != null && $y_resolution != null ) {
                           //$x_res = $x_resolution->getValue();
                           //$y_res = $y_resolution->getValue();
                           $x_resolution->setValue( $y_res );
                           $y_resolution->setValue( $x_res );
                       }*/
                     $image_width = $input_ifd0->getEntry(PelTag::IMAGE_WIDTH);
                     $image_length = $input_ifd0->getEntry(PelTag::IMAGE_LENGTH);
                     if ($image_width != null && $image_length != null) {
                         $image_width->setValue($size[0]);
                         $image_length->setValue($size[1]);
                     }
                 }
                 if (!empty($input_exif_ifd)) {
                     $x_dimention = $input_exif_ifd->getEntry(PelTag::PIXEL_X_DIMENSION);
                     $y_dimention = $input_exif_ifd->getEntry(PelTag::PIXEL_Y_DIMENSION);
                     if ($x_dimention != null && $y_dimention != null) {
                         $x_dimention->setValue($size[0]);
                         $y_dimention->setValue($size[1]);
                     }
                 }
                 if (!empty($input_inter_ifd)) {
                     $rel_image_width = $input_inter_ifd->getEntry(PelTag::RELATED_IMAGE_WIDTH);
                     $rel_image_length = $input_inter_ifd->getEntry(PelTag::RELATED_IMAGE_LENGTH);
                     if ($rel_image_width != null && $rel_image_length != null) {
                         $rel_image_width->setValue($size[0]);
                         $rel_image_length->setValue($size[1]);
                     }
                 }
                 $output_jpeg = new PelJpeg($to_file);
                 $output_jpeg->setExif($input_exif);
                 /* We can now save the image with input_exif. */
                 $output_jpeg->saveFile($to_file);
             }
         } catch (PelException $e) {
         }
     }
 }
开发者ID:pasyuk,项目名称:grand-media,代码行数:75,代码来源:core.php

示例9: createNewImageGD

 private function createNewImageGD($sourcePathBase, $targetPath, $newWidth, $newHeight, $sourceWidth, $sourceHeight)
 {
     $status = false;
     if (!$this->sourceGdImg) {
         $this->sourceGdImg = imagecreatefromjpeg($sourcePathBase);
         if (class_exists('PelJpeg')) {
             $inputJpg = new PelJpeg($sourcePathBase);
             $this->exif = $inputJpg->getExif();
         }
     }
     ini_set('memory_limit', '512M');
     $tmpImg = imagecreatetruecolor($newWidth, $newHeight);
     //imagecopyresampled($tmpImg,$sourceImg,0,0,0,0,$newWidth,$newHeight,$sourceWidth,$sourceHeight);
     imagecopyresized($tmpImg, $this->sourceGdImg, 0, 0, 0, 0, $newWidth, $newHeight, $sourceWidth, $sourceHeight);
     if ($this->jpgCompression) {
         $status = imagejpeg($tmpImg, $targetPath, $this->jpgCompression);
         if ($this->exif && class_exists('PelJpeg')) {
             $outputJpg = new PelJpeg($targetPath);
             $outputJpg->setExif($this->exif);
             $outputJpg->saveFile($targetPath);
         }
     } else {
         if ($this->exif && class_exists('PelJpeg')) {
             $outputJpg = new PelJpeg($tmpImg);
             $outputJpg->setExif($this->exif);
             $status = $outputJpg->saveFile($targetPath);
         } else {
             $status = imagejpeg($tmpImg, $targetPath);
         }
     }
     if (!$status) {
         $this->logOrEcho("\tERROR: Unable to resize and write file: " . $targetPath . "\n");
     }
     imagedestroy($tmpImg);
     return $status;
 }
开发者ID:ranglin,项目名称:TcnImageTools,代码行数:36,代码来源:TcnImageProcessing.php


注:本文中的PelJpeg::saveFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。