I have tried following typo-script to generate thumbnail. It is not working for me.
Please help.
$cObj = t3lib_div::makeInstance('tslib_cObj');
$image_conf['file'] = 'uploads/pics/filename.jpg';
$image_conf['file.']['width'] = $width;
$image_conf['file.']['height'] = $height;
$newThumb = $cObj->IMAGE($image_conf);
print $newThumb;
I want to generate thumbnail from jpg,jpeg,png formats
In your plugin you can use
$this->cObj->IMAGE($image_conf);
to scale an image.
As the cObject has some dependencies, an instance of t3lib_div::makeInstance('tslib_cObj'); wont be sufficient to scale images.
Related
I have a richTextBox and I add text and image. Text are not the same color and font. I want to convert to all things for doc file. I am using this codes for this.
wordeaktar.Application wordapp = new wordeaktar.Application();
wordapp.Visible = true;
wordeaktar.Document worddoc;
object wordobj = System.Reflection.Missing.Value;
worddoc = wordapp.Documents.Add(ref wordobj);
wordapp.Selection.TypeText(richTextBox1.Text);
wordapp = null;
enter image description here
This is the image of my richTextBox. How can I do that?
#Gserg's Answer is right!
"richTextBox1.SelectAll(); richTextBox1.Copy(); worddoc.Range().Paste();. However if you simply richTextBox1.SaveFile("...", RichTextBoxStreamType.RichText), Word will be perfectly happy with that. – GSerg"
tldr: How do I render a TypoScript COA Object with a GIFBUILDER image from inside a CommandController?
I'm currently developing an eCommerce platform for which I need to periodically import an excel file that holds the product catalog. After a product is created from a row of data in the excel file, a directory is searched for product images related to that item, and they are linked as FileReferences to the product. I've written an ImportCommandController that takes care of that.
This all works like a charm, with the only glaring problem being the performance of the image manipulation. The first call to a product list pages takes a good 30 seconds, the first request of a single view. I periodically need to recreate the whole catalog from scratch, and the source product images are huge files, I have no influence on that.
The product images of that catalog are being generated by a TypoScript that takes care of fitting these images inside a square white background, returning the IMG_RESOURCE url. I call that TypoScript from inside a Fluid template with the cObject ViewHelper.
I've been trying to call this bit of TypoScript from the ImportCommandController->importAction, so that the import cronjob would take care of creating these scaled images beforehand, with the same filename hash, so they're already processed when they're called by the single view. But I can't manage to do that.
The TypoScript in question ist this:
plugin.tx_productfinder_products {
// Productfinder-Produktbilder
// Bilder quadratisch auf weissen Hintergrund einpassen
productimage = COA
productimage {
// Daten der FileReference im Regsiter ablegen
10 = FILES
10 {
references.data = current
renderObj = COA
renderObj {
10 = LOAD_REGISTER
10 {
param = TEXT
param.data = file:current.uid
}
}
}
20 = IMG_RESOURCE
20 {
file = GIFBUILDER
file {
XY = 960,960
format = jpg
quality = 95
backColor = #ffffff
20 = IMAGE
20 {
offset = 960-[20.w]/2,960-[20.h]/2
file {
import.data = current
treatIdAsReference = 1
maxW = 960
maxH = 960
}
}
// // Text aus Daten der FileReference als Wasserzeichen ins Bild rendern
// 30 = TEXT
// 30 {
// //text.data = register:param
// text.data = current
// fontColor= #dddddd
// fontSize = 12
// offset = 20,[20.h]-20
// align = left
// antiAlias = 1
// }
}
}
}
}
And I call these from inside the Fluid template like so:
<img class="img-responsive" src="{f:cObject(typoscriptObjectPath:'plugin.tx_productfinder_products.productpreviewimage', data:'{image.uid}')}">
What have I tried so far? Pretty much everything.
I've first tried to call the ContentObjectRenderer directly,
/** #var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $cObj */
$contentObject = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
$contentObject->setCurrentVal($image->getUid());
$content = $contentObject->cObjGetSingle($this->settings['productimagetest'], $this->settings['productimagetest.']);
resulting in these weird errors.
Oops, an error occurred: PHP Warning: imagejpeg(typo3temp/GB/csm_8000424600_cbbd127be3_9cb1d3c8cc.jpg): failed to open stream: No such file or directory in /html/typo3/typo3_src-7.6.16/typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php line 2912
It seems that the TYPO3 Configuration regarding the Grapics Processing isn't initialized in the same way as it is for the Frontend.
Next, I tried instanciate a StandaloneFluidView to render the whole SingleItem template per item, but I cant figure that out because the Request and Context are missing and so the partials being referenced in the template aren't being rendered.
Then I tired to just create the FrontendUrls per single item and request them from the CommandController,
/** #var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $cObj */
$contentObject = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
$test = $contentObject->typolink_URL(array(
'parameter' => 671,
'additionalParams' =>
'&tx_productfinder_products[product]='.$product->getUid().
'&tx_productfinder_products[action]=show'.
'&tx_productfinder_products[controller]=Product',
'returnLast' => 'url'
));
$this->outputLine(print_r($test,true));
but the URLs generated in this way are missing the cHash.
Can anybody offer help or a different approach to this?
Since these images are generated just once for the frontend output and are then available anyway, I don't see the advantage of generating them beforehand. The white square could be easily generated with CSS, so to me this does not even look like a use case for the GIFBUILDER.
That being said there's still something you could do: Since you are in the PHP context already, why don't you instanciate the GIFBUILDER directly or use even pure IM/GM commands instead of going for an IMG_RESOURCE which is actually meant to be output in the frontend?
I know this is an old question, but I had the same issue and had to invest some time to debug it, so maybe this this answer is useful for someone else in the future.
The CLI uses a different working directory than the frontend, therefore the relative path to typo3temp/ directory used in the GifBuilder class cannot be resolved, which results in the above mentioned warning.
To fix the relative path resolution, you have to change your working directory to the frontend one, this can be achieved by:
class AcmeCommand extends Command
{
protected static $cwdBackup;
protected function execute(InputInterface $input, OutputInterface $output)
{
if (Environment::isCli()) {
static::$cwdBackup = getcwd();
chdir(Environment::getPublicPath());
}
//
if (Environment::isCli()) {
chdir(static::$cwdBackup);
}
}
}
I'm trying to use the share() method, including an image, but I'm having trouble supplying the proper path to the image. Where should I put the image file, and what is the path (putting in the default package and trying "jar:///myimage.png" didn't work), and why is this not documented clearly?
image can be stored in storage which is following path for window
C:\Users\userName.cn1
and the image can be read by using following codes
InputStream is = Storage.getInstance().createInputStream("tizbn.JPG");
EncodedImage i = EncodedImage.create(is, is.available());
Loading image from default folder
Image i =EncodedImage.create("/tizbn.png");
Loading image From Theme
EncodedImage current = (EncodedImage) fetchResourceFile().getImage("tizbn.png");
The share API works with https://www.codenameone.com/javadoc/com/codename1/io/FileSystemStorage.html[FileSystemStorage] and not with https://www.codenameone.com/javadoc/com/codename1/io/Storage.html[Storage].
You need to save the file into a file system path which is always an absolute path, we recommend using the app home to store files. There is a sample in the developer guide section on the ShareButton covering this:
Form hi = new Form("ShareButton");
ShareButton sb = new ShareButton();
sb.setText("Share Screenshot");
hi.add(sb);
Image screenshot = Image.createImage(hi.getWidth(), hi.getHeight());
hi.revalidate();
hi.setVisible(true);
hi.paintComponent(screenshot.getGraphics(), true);
String imageFile = FileSystemStorage.getInstance().getAppHomePath() + "screenshot.png";
try(OutputStream os = FileSystemStorage.getInstance().openOutputStream(imageFile)) {
ImageIO.getImageIO().save(screenshot, os, ImageIO.FORMAT_PNG, 1);
} catch(IOException err) {
Log.e(err);
}
sb.setImageToShare(imageFile, "image/png");
I am trying to resize a given JCR image resource and store it as a new rendition. The use case is to generate thumbnails in "any" scale.
I wanted to use the com.day.cq.dam.core.process.CreateThumbnailProcess, but this it is not available in the project, i am working on.
I found a quite low level approach, to resize an image identified by jcrPathToImage to int targetWidth and int targetHeight.
Resize Image
Resource resource = getResourceResolver().getResource(jcrPathToImage);
Asset asset = resource.adaptTo(Asset.class);
Layer layer = new Layer(asset.getOriginal().getStream())
layer.resize(targetWidth, targetHeight);
Create new rendition in JCR
Extract mime type of the original image
Image image = new Image(resource);
String mimeType = image.getMimeType();
Store the resized Image using its asset representation.
ByteArrayOutputStream bout = null;
ByteArrayInputStream bin = null;
try {
bout = new ByteArrayOutputStream(2048);
layer.write(mimeType, 1, bout);
bin = new ByteArrayInputStream(bout.toByteArray());
asset.addRendition(resizedImgName, bin, mimeType);
} finally {
// close streams ...
}
you can configure the DAM Update Asset workflow to give the renditions you want to get created
http://localhost:4502/etc/workflow/models/dam/update_asset.html
in this workflow model select the thumbnail creation step and in the process tab of that step you can add your custom thumbnail values
[140:100],[48:48],[319:319],[90,90]
I have problems creating a template for my pdf documents in Zend_Pdf. I've followed the guide provided at http://framework.zend.com/manual/en/zend.pdf.pages.html but it doesn't seem to work since no footer text or logo are visible at any page except the first.
This is a sample of my code: (Note; the MTP constant is just the recalculate from mm to points)
//Create pdf object
$pdf = new Zend_Pdf();
//Create the first page
$page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
/*HEADER*/
//insert logo at the top
$logo = Zend_Pdf_Image::imageWithPath(APPLICATION_PATH . '/../document_root/images/logotype.png');
$page->drawImage($logo, 22*MTP,274*MTP, 62*MTP, 289*MTP);
/*FOOTER*/
$footerStyle->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 10);
$page->setStyle($footerStyle);
$page->drawText('Footer text', 33*MTP, 20*MTP, 'ISO-8859-1');
//save the page to pdf->pages
$pdf->pages[0] = $page;
//save the page as a template
$template = $pdf->pages[0];
//create the next page from template
$page1 = new Zend_Pdf_Page($template);
//save the next page to pdf->pages
$pdf->pages[] = $page1;
Have I completely misunderstood how this "template function" work in Zend_Pdf? I know that Zend_Pdf lacks quite a number of features compaired to some of the external pdf-generators (like FPDF) but still, there must be some way to make a basic header/footer for all pages right?
Try to use clone instead passing page as argument to a new page.
$page1 = clone $template;
or simply
$pdf->pages[] = clone $pdf->pages[0];