本文整理汇总了PHP中sfImage::loadString方法的典型用法代码示例。如果您正苦于以下问题:PHP sfImage::loadString方法的具体用法?PHP sfImage::loadString怎么用?PHP sfImage::loadString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfImage
的用法示例。
在下文中一共展示了sfImage::loadString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: opp_sync_politician_image
/**
* fetch today's news regarding objects monitored by the user
*
* @param string $user - OppUser object
* @return void
* @author Guglielmo Celata
*/
function opp_sync_politician_image($pol)
{
$start_time = microtime(true);
$success = true;
echo pakeColor::colorize(sprintf('Processing politician %s...', $pol), array('fg' => 'red', 'bold' => true));
// invoke the remote getPolImage function to grab the images from op_openpolis
$remote_img_url = sfConfig::get('app_remote_politicians_images_service_url') . '/' . sfConfig::get('app_remote_openpolis_api_key') . '/' . $pol->getId();
/* debug
echo pakeColor::colorize(sprintf('Url: %s...', $remote_img_url),
array('fg' => 'red', 'bold' => true));
*/
$file = fopen($remote_img_url, "r");
if (!$file) {
$err = "unable to open remote file.";
$success = false;
}
$remote_img_str = '';
while (!feof($file)) {
$remote_img_str .= fgets($file, 1024);
}
fclose($file);
$images_root = SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'web' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'parlamentari' . DIRECTORY_SEPARATOR;
// resizes images and stores them in the FS
$picture = new sfImage();
$picture->setMimeType('image/jpeg');
$picture->loadString($remote_img_str);
$picture->resize(91, null);
$picture->saveAs($images_root . 'picture/' . $pol->getId() . '.jpeg', 'image/jpeg');
$thumb = new sfImage();
$thumb->setMimeType('image/jpeg');
$thumb->loadString($remote_img_str);
$thumb->resize(40, null);
$thumb->saveAs($images_root . 'thumb/' . $pol->getId() . '.jpeg', 'image/jpeg');
$execution_time = microtime(true) - $start_time;
if ($success) {
echo " ok (";
} else {
echo " {$err} (";
}
echo pakeColor::colorize(sprintf("%f", $execution_time), array('fg' => 'cyan'));
echo ")\n";
}
示例2: updateRemoteImage
protected function updateRemoteImage($image, Swift_Message $message, $templateName)
{
$fileName = dmOs::join(sfConfig::get('sf_web_dir'), 'cache/mail_templates', md5($image->src . $image->width . $image->height) . pathinfo($image->src, PATHINFO_EXTENSION));
if (!file_exists($fileName)) {
$imageData = file_get_contents($image->src);
if (!$imageData) {
$this->logError($templateName, 'remote', 'image', $image->src);
$image->src = '';
return $image;
} else {
$sfImage = new sfImage();
$sfImage->loadString($imageData);
$width = $sfImage->getWidth();
$height = $sfImage->getHeight();
if (isset($image->width) && strpos($image->width, '%') === false) {
$width = $image->width;
}
if (isset($image->height) && strpos($image->height, '%') === false) {
$width = $image->height;
}
$sfImage->setQuality(dmConfig::get('image_resize_quality'));
$sfImage->thumbnail($width, $height, dmConfig::get('image_resize_method'), null);
$fileSystem = $this->serviceContainer->getService('filesystem');
if (!file_exists(dirname($fileName))) {
$fileSystem->mkdir(dirname($fileName));
}
$sfImage->saveAs($fileName);
chmod($fileName, 0777);
}
}
if (dmConfig::get('mail_template_embed_remote_images_as_attachments', true)) {
$image->src = $message->embed(Swift_Image::fromPath($fileName));
} else {
$image->src = $this->basePath . str_replace(sfConfig::get('sf_web_dir'), '', $fileName);
}
return $image;
}