First of all you should say what TYPO3 version you use and if your extension uses Extbase or the old pibased code.
I guess it's Extbase since you inherit from a namespaced viewhelper. My advice would be to take a look at the original f:image
viewhelper code (TYPO3\CMS\Fluid\ViewHelpers\ImageViewHelper
) and copy what you need.
first add this to the top part of you viewhelper:
/**
* @var \TYPO3\CMS\Extbase\Service\ImageService
* @inject
*/
protected $imageService;
Then the code in your method
$image = $this->imageService->getImage($imgPath);
// you have to set these variables or remove if you don't need them
$processingInstructions = array(
'width' => $width,
'height' => $height,
'minWidth' => $minWidth,
'minHeight' => $minHeight,
'maxWidth' => $maxWidth,
'maxHeight' => $maxHeight,
'crop' => $crop,
);
$processedImage = $this->imageService->applyProcessingInstructions($image, $processingInstructions);
$imageUri = $this->imageService->getImageUri($processedImage);
$imageUri
now holds the path to the resized image.
PS: The example you copied is from the old pibased system that no longer exists since the 7.x branch.