Typo3 Fluid - Responsive image viewhelper - typo3

In my extension I'm using the Typo3 image manipulation. I would like to render the picture responsive with the srcset attribute. Therefore I'm using the VHS media.image viewhelper. The problem I have is that this viewhelper doesn't support the Typo3 native crop functionality. And the Fluid image viewhelper doesn't support the srcset functionality.
Is there a easy solution for this problem or do I need to write a custom viewhelper?
<f:image treatIdAsReference="true" src="{image.id}" alt="{image.alternative}" title="{image.title}" crop="{image.crop}" />
<v:media.image src="{image.id}" alt="{image.alternative}" title="{image.title}" srcset="480,768,992,1200" />
I'm happy for every help.

This feature is not yet implemented in VHS. I just created a pull request which can be found at https://github.com/FluidTYPO3/vhs/pull/1091/commits/761435c82786cf9da6626d849a39c6a9124bfdff.
Just override the related file and it should be fine!

I changed the SourceSetViewHelperTrait.php. Now the rendering is working. treatIdAsReference must be true otherwise the processed image will be used to create the srcset images.
<?php
namespace FluidTYPO3\Vhs\Traits;
use FluidTYPO3\Vhs\Utility\FrontendSimulationUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
/**
* This trait can be used by viewhelpers that generate image tags
* to add srcsets based to the imagetag for better responsiveness
*/
trait SourceSetViewHelperTrait
{
/**
* used to attach srcset variants of a given image to the specified tag
*
* #param \TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder $tag the tag to add the srcset as argument
* #param string $src image path to render srcsets for
* #return array
*/
public function addSourceSet($tag, $src)
{
$srcsets = $this->getSourceSetWidths();
if ('BE' === TYPO3_MODE) {
FrontendSimulationUtility::simulateFrontendEnvironment();
}
$width = $this->arguments['width'];
$height = $this->arguments['height'];
$format = $this->arguments['format'];
$quality = $this->arguments['quality'];
$dimensions = [
'ratio'=>0,
];
$treatIdAsReference = (boolean) $this->arguments['treatIdAsReference'];
if (true === $treatIdAsReference) {
$src = $this->arguments['src'];
$crop = $this->arguments['crop'];
if ($crop === null) {
$crop = $src instanceof FileReference ? $src->getProperty('crop') : null;
}
$dimensions = $this->getDimensions($width, $height);
}
$imageSources = [];
$srcsetVariants = [];
foreach ($srcsets as $key => $width) {
if (0 < $dimensions['ratio']) {
$height = floor((int)$width/$dimensions['ratio']) . $dimensions['postHeight'];
}
$width = $width . $dimensions['postWidth'];
$srcsetVariant = $this->getImgResource($src, $width, $height, $format, $quality, $treatIdAsReference, $crop);
$srcsetVariantSrc = rawurldecode($srcsetVariant[3]);
$srcsetVariantSrc = $this->preprocessSourceUri(GeneralUtility::rawUrlEncodeFP($srcsetVariantSrc));
$imageSources[$srcsetVariant[0]] = [
'src' => $srcsetVariantSrc,
'width' => $srcsetVariant[0],
'height' => $srcsetVariant[1],
];
$srcsetVariants[$srcsetVariant[0]] = $srcsetVariantSrc . ' ' . $srcsetVariant[0] . 'w';
}
$tag->addAttribute('srcset', implode(',', $srcsetVariants));
if ('BE' === TYPO3_MODE) {
FrontendSimulationUtility::resetFrontendEnvironment();
}
return $imageSources;
}
/**
* generates a copy of a give image with a specific width
*
* #param string $src path of the image to convert
* #param integer $width width to convert the image to
* #param integer $height height to convert the image to
* #param string $format format of the resulting copy
* #param string $quality quality of the resulting copy
* #param string $treatIdAsReference given src argument is a sys_file_reference record
* #param string $crop image crop string
* #param array $params additional params for the image rendering
* #return string
*/
public function getImgResource($src, $width, $height, $format, $quality, $treatIdAsReference, $crop, $params = null)
{
$setup = [
'width' => $width,
'height' => $height,
'treatIdAsReference' => $treatIdAsReference,
'crop' => $crop,
];
if (false === empty($format)) {
$setup['ext'] = $format;
}
if (0 < intval($quality)) {
$quality = MathUtility::forceIntegerInRange($quality, 10, 100, 75);
$setup['params'] .= ' -quality ' . $quality;
}
if ('BE' === TYPO3_MODE && '../' === substr($src, 0, 3)) {
$src = substr($src, 3);
}
return $this->contentObject->getImgResource($src, $setup);
}
/**
* returns an array of srcsets based on the mixed ViewHelper
* input (list, csv, array, iterator)
*
* #return array
*/
public function getSourceSetWidths()
{
$srcsets = $this->arguments['srcset'];
if (true === $srcsets instanceof \Traversable) {
$srcsets = iterator_to_array($srcsets);
} elseif (true === is_string($srcsets)) {
$srcsets = GeneralUtility::trimExplode(',', $srcsets, true);
} else {
$srcsets = (array) $srcsets;
}
return $srcsets;
}
private function getDimensions($width, $height)
{
$widthSplit = [];
$heightSplit = [];
if (false === empty($width)) {
preg_match("/(\\d+)([a-zA-Z]+)/", $width, $widthSplit);
}
if (false === empty($height)) {
preg_match("/(\\d+)([a-zA-Z]+)/", $height, $heightSplit);
}
$dimensions = [
'width'=>(int)$widthSplit[1],
'height'=>(int)$heightSplit[1],
'postWidth'=>$widthSplit[2],
'postHeight'=>$heightSplit[2],
'ratio'=> 0,
];
if (0 < $dimensions['height']) {
$dimensions['ratio'] = $dimensions['width']/$dimensions['height'];
}
return $dimensions;
}
}

Related

Too many Redirects with Controller

When I try to define my routes with an ImagesController, I get a "site redirected you too many times" error when going to what should be the index. I'm stumped. Am I over-tired and not seeing something obvious?
web.php
Route::prefix('images')->group(function(){
Route::post('add-tag', 'ImagesController#addTag');
Route::get('test', 'ImagesController#index');
});
When I access /images/test, the controller responds correctly. When I have it defined as '' or / it redirects too much. I'm not setting them simultaneously.
Route::prefix('images')->group(function(){
Route::post('add-tag', 'ImagesController#addTag');
// like this:
Route::get('', 'ImagesController#index');
// or like the following:
Route::get('/', 'ImagesController#index');
});
I've even tried to define /images before the prefix group to no avail. images/test is fine in this case.
Route::get('images', 'ImagesController#index');
Route::prefix('images')->group(function(){
Route::post('add-tag', 'ImagesController#addTag');
Route::get('test', 'ImagesController#index');
});
ImagesController.php
namespace App\Http\Controllers;
use \Auth;
use App\Helpers;
use App\Image;
use App\Tag;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Symfony\Component\Console\Helper\Helper;
class ImagesController extends Controller
{
private $sortBy = [
'created_at',
'updated_at',
'orig_name',
'orig_size'
];
private $defaultSortBy = 'created_at';
private $defaultOrder = 'desc';
/**
* #param Request $request
* #return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function index(Request $request)
{
$sort = $request->get('sort', $this->defaultSortBy);
$sort = in_array($sort, $this->sortBy) ? $sort : 'created_at';
$order = $request->get('order', $this->defaultOrder);
$order = $order == 'desc' ? 'desc' : 'asc';
$images = Image::orderBy($sort, $order)
->whereQuestionable(0)
->wherePrivate(0)
->paginate(config('image.images_per_page'));
if ($images !== null && $sort !== $this->defaultSortBy) {
$images->appends(['sort' => $sort]);
}
if ($images !== null && $order !== $this->defaultOrder) {
$images->appends(['order' => $order]);
}
return view(
'images.index',
[
'images' => $images,
'sort' => $sort,
'order' => $order
]
);
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
//this function works correctly, but I suppose it may be interfering?
public function addTag(Request $request)
{
Log::debug(print_r($request->all(), true));
$error = '';
$uid = trim($request->input('uid', ''));
$newTag = Helpers::prepTag($request->input('tag', ''));
if (!Auth::check()){
$error .= 'You can only add tags to images if you are logged in.';
} else if ($uid === '' || $newTag === '') {
$error .= 'UID and tag cannot be empty';
} else {
$image = Image::whereUid($uid)->unQuestionable()->first();
$currentTags = [];
if (count($image->tags)){
foreach ($image->tags as $currentTag) {
$currentTags[$currentTag->id] = $currentTag->tag;
}
}
if ($image === null) {
$error .= "Image $uid was not found.";
} else {
$tag = Tag::firstOrNew(['tag'=>$newTag]);
if ($tag->ip == '') {
$tag->ip = $request->getClientIp();
$tag->user_id = Auth::check() ? Auth::user()->id : 5;
$tag->save();
}
//\Log::info(print_r($currentTags, true));
//\Log::info(print_r($tag, true));
$addTag = !(bool)isset($currentTags[$tag->id]);
$image->tags()->sync([$tag->id], false);
}
}
if ($request->ajax()) {
if ($error !== '') {
return response()->json(['message' => $error],400);
}
return response()->json(['tagId' => $tag->id, 'imageUid' => $image->uid, 'tag' => $tag->tag, 'isAdmin' => true, 'addTag' => $addTag]);
} else {
if ($error !== '') {
Helpers::alert(3, $error, 'Tag Not Added');
}
return redirect('/');
}
}
}
As I have a model named Images implicit binding was interfering with my defined routes for a controller with the name ImagesController, and applying the prefix /images. After changing the name in the routing to image this issue went away.

How can I get the TYPO3 "appearance" media images by using "ViewHelper"?

thanks for reading and answering...
I have some TYPO3 gridelements in my TYPO3 pagecontent.
Each gridelement has a tab "appearance", where I define an image file.
The database relation from tt_content to the media image are in sys_file_reference.
My question is how can I get this image file in my fluid template by using the ViewHelper and the uid of my gridelement?
I wrote an little ViewHelper (tested on 7.6, but should not need so much changes for 8.7) to get referenced images for an newsletter layout:
<?php
namespace Vendor\Extension\ViewHelpers;
use TYPO3\CMS\Core\Log\LogManager;
use TYPO3\CMS\Core\Resource\FileRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Resource\FileReference;
use TYPO3\CMS\Core\Resource\Exception;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
class ImagesReferencesViewHelper extends AbstractViewHelper implements CompilableInterface
{
/**
* Iterates through elements of $each and renders child nodes
*
* #param int $uid The ID of the element
* #param string $table The Referenced table name
* #param string $fieldName The Referenced field name
* #param string $as The name of the iteration variable
* #param string $key The name of the variable to store the current array key
* #param boolean $reverse If enabled, the iterator will start with the last element and proceed reversely
* #param string $iteration The name of the variable to store iteration information (index, cycle, isFirst, isLast, isEven, isOdd)
* #param string $link The name of the variable to store link
*
* #return string Rendered string
* #api
*/
public function render($uid, $table = 'tt_content', $fieldName = 'assets', $as, $key = '', $reverse = false, $iteration = null, $link = null)
{
return self::renderStatic($this->arguments, $this->buildRenderChildrenClosure(), $this->renderingContext);
}
/**
* #param array $arguments
* #param \Closure $renderChildrenClosure
* #param \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext
*
* #return string
* #throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception
*/
static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext)
{
$templateVariableContainer = $renderingContext->getTemplateVariableContainer();
if ($arguments['uid'] === null || $arguments['table'] === null || $arguments['fieldName'] === null) {
return '';
}
/** #var FileRepository $fileRepository */
$fileRepository = GeneralUtility::makeInstance(FileRepository::class);
$images = array();
try {
$images = $fileRepository->findByRelation($arguments['table'], $arguments['fieldName'], $arguments['uid']);
} catch (Exception $e) {
/** #var \TYPO3\CMS\Core\Log\Logger $logger */
$logger = GeneralUtility::makeInstance(LogManager::class)->getLogger();
$logger->warning('The file-reference with uid "' . $arguments['uid'] . '" could not be found and won\'t be included in frontend output');
}
if (is_object($images) && !$images instanceof \Traversable) {
throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception('ImagesReferencesViewHelper only supports arrays and objects implementing \Traversable interface', 1248728393);
}
if ($arguments['reverse'] === true) {
// array_reverse only supports arrays
if (is_object($images)) {
$images = iterator_to_array($images);
}
$images = array_reverse($images);
}
$iterationData = array(
'index' => 0,
'cycle' => 1,
'total' => count($images)
);
$output = '';
foreach ($images as $keyValue => $singleElement) {
$templateVariableContainer->add($arguments['as'], $singleElement);
/** #var FileReference $singleElement */
if ($arguments['link'] !== null && $singleElement->getLink()) {
$link = $singleElement->getLink();
/** #var ContentObjectRenderer $contentObject */
$contentObject = GeneralUtility::makeInstance(ContentObjectRenderer::class);
$newLink = $contentObject->typoLink_URL(array('parameter' => $link));
$templateVariableContainer->add($arguments['link'], $newLink);
}
if ($arguments['key'] !== '') {
$templateVariableContainer->add($arguments['key'], $keyValue);
}
if ($arguments['iteration'] !== null) {
$iterationData['isFirst'] = $iterationData['cycle'] === 1;
$iterationData['isLast'] = $iterationData['cycle'] === $iterationData['total'];
$iterationData['isEven'] = $iterationData['cycle'] % 2 === 0;
$iterationData['isOdd'] = !$iterationData['isEven'];
$templateVariableContainer->add($arguments['iteration'], $iterationData);
$iterationData['index']++;
$iterationData['cycle']++;
}
$output .= $renderChildrenClosure();
$templateVariableContainer->remove($arguments['as']);
if ($arguments['link'] !== null && $singleElement->getLink()) {
$templateVariableContainer->remove($arguments['link']);
}
if ($arguments['key'] !== '') {
$templateVariableContainer->remove($arguments['key']);
}
if ($arguments['iteration'] !== null) {
$templateVariableContainer->remove($arguments['iteration']);
}
}
return $output;
}
}

ZF2 fileprg with files in collection

I can't get fileprg plugin to work with the files in a collection.
I am trying to upload multiple files using FormCollections, but in $form->getData() there is no key related to my collection or the files .
I tested the form and fileprg with simple file input (in the same form) and it worked uploaded/renamed and it was in the $form->getData().
what am i missing ? is there anything special to be done with the collections to get it to work ?
In the file \Zend\Mvc\Controller\Plugin\FilePostRedirectGet the two functions you want to look at are getNonEmptyUploadData (that is supplying a callback function) and traverseInputs (which is a glorified foreach that checks each input filter then runs it and the value through the above callback).
To allow this plugin to work on collections you will need to extend the class and alter the above functions:
/**
* Traverse the InputFilter and run a callback against each Input and associated value
*
* #param InputFilterInterface $inputFilter
* #param array $values
* #param callable $callback
* #return array|null
*/
protected function traverseInputs(InputFilterInterface $inputFilter, $values, $callback)
{
$returnValues = null;
foreach ($values as $name => $value) {
if (!$inputFilter->has($name)) {
continue;
}
$input = $inputFilter->get($name);
if ($input instanceof InputFilterInterface && is_array($value)) {
if ($input instanceof CollectionInputFilter) {
$retVal = null;
foreach ($value as $k => $val) {
$retVal2 = $this->traverseInputs($input->getInputFilter(), $val, $callback);
if ($retVal2)
$retVal[$k] = $retVal2;
}
} else
$retVal = $this->traverseInputs($input, $value, $callback);
if (null !== $retVal) {
$returnValues[$name] = $retVal;
}
continue;
}
$retVal = $callback($input, $value);
if (null !== $retVal) {
$returnValues[$name] = $retVal;
}
}
return $returnValues;
}
/**
* Traverse the InputFilter and only return the data of FileInputs that have an upload
*
* #param InputFilterInterface $inputFilter
* #param array $data
* #return array
*/
protected function getNonEmptyUploadData(InputFilterInterface $inputFilter, $data)
{
return $this->traverseInputs(
$inputFilter,
$data,
function ($input, $value) {
$messages = $input->getMessages();
if (is_array($value) && $input instanceof FileInput && empty($messages)) {
$rawValue = $value;
if (
(isset($rawValue['error']) && $rawValue['error'] !== UPLOAD_ERR_NO_FILE)
|| (isset($rawValue[0]['error']) && $rawValue[0]['error'] !== UPLOAD_ERR_NO_FILE)
) {
return $value;
}
}
return;
}
);
}
Here is a diff that shows what lines were altered: https://github.com/rafam31/zf2/commit/c481e7404faf93beb4c67a6a4b7490fec15d279b

How to resize uploaded image in zend framework

I have a form with upload image field. How to resize the recently uploaded image to desired size?
My current form is :
<?php
class Application_Form_User extends Zend_Form
{
public function init()
{
$this->setAttrib('enctype', 'multipart/form-data');
$this->setAction("");
$this->setMethod("post");
$element = new Zend_Form_Element_File('photo');
$element->setLabel('Upload an image:')
->setValueDisabled(true);
$this->addElement($element, 'photo');
$element->addValidator('Count', false, 1);
// limit to 1000K
$element->addValidator('Size', false, 1024000);
// only JPEG, PNG, and GIFs
$element->addValidator('Extension', false, 'jpg,png,gif');
$submit = $this->createElement('submit', 'submit');
$submit->setLabel('Save');
$this->addElement($submit);
}
}
And my controller:
public function indexAction()
{
$form=new Application_Form_User();
if ($this->getRequest()->isPost()) {
$formData = $this->getRequest()->getPost();
if ($form->isValid($formData)) {
$file=pathinfo($form->photo->getFileName());
$form->photo->addFilter('Rename', PUBLIC_PATH.'/images/'.uniqid().time().'.'.$file['extension']);
if ($form->photo->receive()) {
$this->view->photo=pathinfo($form->photo->getFileName());
}
}
}
$this->view->form=$form;
}
Can somebody provide me with an example? How can i use plugins like php thumbnailer or similar plugin to resize the uploaded image?
Skoch_Filter_File_Resize works. It is a custom filter: http://eliteinformatiker.de/2011/09/02/thumbnails-upload-and-resize-images-with-zend_form_element_file/
<?php
// Skoch/Filter/File/Resize.php
/**
* Zend Framework addition by skoch
*
* #category Skoch
* #package Skoch_Filter
* #license http://opensource.org/licenses/gpl-license.php GNU Public License
* #author Stefan Koch <cct#stefan-koch.name>
*/
/**
* #see Zend_Filter_Interface
*/
require_once 'Zend/Filter/Interface.php';
/**
* Resizes a given file and saves the created file
*
* #category Skoch
* #package Skoch_Filter
*/
class Skoch_Filter_File_Resize implements Zend_Filter_Interface
{
protected $_width = null;
protected $_height = null;
protected $_keepRatio = true;
protected $_keepSmaller = true;
protected $_directory = null;
protected $_adapter = 'Skoch_Filter_File_Resize_Adapter_Gd';
/**
* Create a new resize filter with the given options
*
* #param Zend_Config|array $options Some options. You may specify: width,
* height, keepRatio, keepSmaller (do not resize image if it is smaller than
* expected), directory (save thumbnail to another directory),
* adapter (the name or an instance of the desired adapter)
* #return Skoch_Filter_File_Resize An instance of this filter
*/
public function __construct($options = array())
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
} elseif (!is_array($options)) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('Invalid options argument provided to filter');
}
if (!isset($options['width']) && !isset($options['height'])) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('At least one of width or height must be defined');
}
if (isset($options['width'])) {
$this->_width = $options['width'];
}
if (isset($options['height'])) {
$this->_height = $options['height'];
}
if (isset($options['keepRatio'])) {
$this->_keepRatio = $options['keepRatio'];
}
if (isset($options['keepSmaller'])) {
$this->_keepSmaller = $options['keepSmaller'];
}
if (isset($options['directory'])) {
$this->_directory = $options['directory'];
}
if (isset($options['adapter'])) {
if ($options['adapter'] instanceof Skoch_Filter_File_Resize_Adapter_Abstract) {
$this->_adapter = $options['adapter'];
} else {
$name = $options['adapter'];
if (substr($name, 0, 33) != 'Skoch_Filter_File_Resize_Adapter_') {
$name = 'Skoch_Filter_File_Resize_Adapter_' . ucfirst(strtolower($name));
}
$this->_adapter = $name;
}
}
$this->_prepareAdapter();
}
/**
* Instantiate the adapter if it is not already an instance
*
* #return void
*/
protected function _prepareAdapter()
{
if ($this->_adapter instanceof Skoch_Filter_File_Resize_Adapter_Abstract) {
return;
} else {
$this->_adapter = new $this->_adapter();
}
}
/**
* Defined by Zend_Filter_Interface
*
* Resizes the file $value according to the defined settings
*
* #param string $value Full path of file to change
* #return string The filename which has been set, or false when there were errors
*/
public function filter($value)
{
if ($this->_directory) {
$target = $this->_directory . '/' . basename($value);
} else {
$target = $value;
}
return $this->_adapter->resize($this->_width, $this->_height,
$this->_keepRatio, $value, $target, $this->_keepSmaller);
}
}
<?php
// Skoch/Filter/File/Resize/Adapter/Abstract.php
/**
* Zend Framework addition by skoch
*
* #category Skoch
* #package Skoch_Filter
* #license http://opensource.org/licenses/gpl-license.php GNU Public License
* #author Stefan Koch <cct#stefan-koch.name>
*/
/**
* Resizes a given file and saves the created file
*
* #category Skoch
* #package Skoch_Filter
*/
abstract class Skoch_Filter_File_Resize_Adapter_Abstract
{
abstract public function resize($width, $height, $keepRatio, $file, $target, $keepSmaller = true);
protected function _calculateWidth($oldWidth, $oldHeight, $width, $height)
{
// now we need the resize factor
// use the bigger one of both and apply them on both
$factor = max(($oldWidth/$width), ($oldHeight/$height));
return array($oldWidth/$factor, $oldHeight/$factor);
}
}
<?php
// Skoch/Filter/File/Resize/Adapter/Gd.php
/**
* Zend Framework addition by skoch
*
* #category Skoch
* #package Skoch_Filter
* #license http://opensource.org/licenses/gpl-license.php GNU Public License
* #author Stefan Koch <cct#stefan-koch.name>
*/
require_once 'Skoch/Filter/File/Resize/Adapter/Abstract.php';
/**
* Resizes a given file with the gd adapter and saves the created file
*
* #category Skoch
* #package Skoch_Filter
*/
class Skoch_Filter_File_Resize_Adapter_Gd extends
Skoch_Filter_File_Resize_Adapter_Abstract
{
public function resize($width, $height, $keepRatio, $file, $target, $keepSmaller = true)
{
list($oldWidth, $oldHeight, $type) = getimagesize($file);
switch ($type) {
case IMAGETYPE_PNG:
$source = imagecreatefrompng($file);
break;
case IMAGETYPE_JPEG:
$source = imagecreatefromjpeg($file);
break;
case IMAGETYPE_GIF:
$source = imagecreatefromgif($file);
break;
}
if (!$keepSmaller || $oldWidth > $width || $oldHeight > $height) {
if ($keepRatio) {
list($width, $height) = $this->_calculateWidth($oldWidth, $oldHeight, $width, $height);
}
} else {
$width = $oldWidth;
$height = $oldHeight;
}
$thumb = imagecreatetruecolor($width, $height);
imagealphablending($thumb, false);
imagesavealpha($thumb, true);
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $width, $height, $oldWidth, $oldHeight);
switch ($type) {
case IMAGETYPE_PNG:
imagepng($thumb, $target);
break;
case IMAGETYPE_JPEG:
imagejpeg($thumb, $target);
break;
case IMAGETYPE_GIF:
imagegif($thumb, $target);
break;
}
return $target;
}
}
$photo->addFilter(new Skoch_Filter_File_Resize(array(
'width' => 200,
'height' => 300,
'keepRatio' => true,
)));

using Zend_Service_Ebay_Finding to retrieve sellers items

I wish to retrieve all sellers items using the findItemsAdvanced call of Zend_Service_Ebay_Finding API. I'm a bit confused as to how to use it? has anyone got a example of how this method works? I tried
$response = $finding->findItemsAdvanced('seller=<SELLERNAME>');
But gives me nothing?
Would appreciate any help
In the end I overloaded the Zend_Service_Ebay_Finding API and added 2 methods to grab me all the seller info. Maybe this will help anyone else with the same issue.
/**
* Finds items for a specific seller
* and a page
*
* #param string $seller
* #param int $page
* #return Zend_Service_Ebay_Finding_Response_Items
*/
public function sellerItems($seller, $page = 1){
// prepare options
$options = array('itemFilter(0).name' => 'Seller', 'itemFilter(0).value(0)' => $seller, 'paginationInput.entriesPerPage' => 100);
// do request
return $this->_findItems($options, 'findItemsAdvanced');
}
/**
* Finds items for a specific seller - iterates through pages
* and a page
*
* #param string $seller
* #return array
*/
public function getAllSellerItems($seller) {
$page1 = $this->sellerItems($seller);
$pages = $page1->paginationOutput->totalPages;
$items = $page1->searchResult->item;
$full = array();
foreach($items as $item) {
$full[] = $item;
}
if($pages > 1) {
for($i = 2;$i <= $pages; $i ++) {
$results = $this->sellerItems($seller, $i);
$items = $results->searchResult->item;
foreach($items as $item) {
$full[] = $item;
}
}
}
return $full;
}