I'm looking for a script that uploads and resizes multiple images using php. I'm using a shared hosting so can't install things. I had managed to upload, resize and watermark ONE image but really can't get it to work with multiple files.
Has anyone got something I could start with please?
Thank you
Take a look at ImageWorkshop, which is a good oop image manipulation library in pure PHP (GD), and supports multiple layer.
Simple loop through your files:
foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){
$layer = ImageWorkshop::initFromPath($tmp_name);
$layer->resizeInPixel(400, null, true);
$layer->save($dirPath, $filename, $createFolders, $backgroundColor, $imageQuality);
}
More info in the Quickstart.
Sure you can also write you own Image Library.
Related
how can I create file (PDF file for example) from binary stream I have stored in global? I have stream stored in caché global and I need to create and save the file created by the stream using ObjectScript.
Thanks :)
It is not so easy. There is only one official way to create pdf in Cache, and it is ZEN reports. With ZEN reports you could create not only pdf, also possible to make html, xlsx. ZEN Reports used Apache FOP for generating it, any other ways also possible, but you should do it only by yourself.
Or maybe I misunderstood you, and you mean that your binary stream already contains PDF, and you just want to save it to some file. If so, you just have to copy your globalstream to filestream, with code like this:
set fs=##class(%Stream.FileBinary).%New()
set fs.Filename="c:\temp.pdf"
set tSC=fs.CopyFrom(yourStream)
set tSC=fs.%Save()
I am using Catalyst::View::Wkhtmltopdf but issues are araising,
got the error
Caught exception in wealthe::View::Wkhtmltopdf->process "Void-input at /usr/local/share/perl5/Catalyst/View/Wkhtmltopdf.pm line 98."
When checked found its some issue with template, I have added the following config in myapp.pm
'View::Wkhtmltopdf' => { command => '/usr/local/bin/wkhtmltopdf',
tmpdir => '/usr/tmp',
tt_view => 'TT',
}
Template name is TT.pm under View and TT.pm is rendering correctly,
I have made Wkhtmltopdf.pm file under View with the following contents
package myapp::View::Wkhtmltopdf;
use Moose;
extends qw/Catalyst::View::Wkhtmltopdf/;
PACKAGE->meta->make_immutable();
is there anything else I need to get it working.
My experience with the PDF writing perl modules on CPAN is that every option is either:
extremely simple, but capable of only very rudimentary output
fully featured and capable of professional PDF output, but hideously complex and requiring pretty deep knowledge of PDF internals
We gave up.
Instead of trying to generate PDFs with perl natively from scratch, we attacked the problem by building the pages we wanted to render as PDF with Template Toolkit (in most cases reusing existing templates with different wrappers), and used the excellent wkhtmltopdf to handle the conversion to PDF.
Since then, Catalyst::View::Wkhtmltopdf has become available that makes this even simpler.
One of the easiest way is to create a (quite simple) HTML page then convert it to PDF: https://metacpan.org/pod/PDF::FromHTML
It needs the least amount of PDF knowledge.
The other module could create PDF on the fly but they are much more complicated: https://metacpan.org/pod/PDF::API2
I am wanting to display the album artwork of a song (accessed via the taglib-sharp library) within a Windows Forms picture box. The problem I'm running into is that the taglib-library returns an image of type TagLib.IPicture whereas the picture box requires an object of type System.Drawing.Image.
I have scoured the internet for many hours now, looking for a way to convert from an IPicture to Image, but to no avail. The best lead I have is this: http://msdn.microsoft.com/en-us/library/system.windows.forms.axhost.getpicturefromipicture.aspx, but I have yet to see a successful example of how to implement this.
Any help as to how to convert between these two types would be much appreciated. Note: IPicture is not analogous to IPictureDisp in this case.
I've done the opposite before - turning an existing .jpg into an IPicture for embedding in an .mp3 file. I just tried reversing that operation and, after tweaking and testing, came up with this:
TagLib.File tagFile = TagLib.File.Create(mp3FilePath);
MemoryStream ms = new MemoryStream(tagFile.Tag.Pictures[0].Data.Data);
System.Drawing.Image image = System.Drawing.Image.FromStream(ms);
Thanks for the question - I already know how I'm going to use this myself!
Update: Here's the other way (.jpg to IPicture that I've done before):
tagFile.Tag.Pictures = new TagLib.IPicture[]
{
new TagLib.Picture(new TagLib.ByteVector((byte[])new System.Drawing.ImageConverter().ConvertTo(System.Drawing.Image.FromFile(jpgFilePath), typeof(byte[]))))
};
I want to use Catalyst to process all requests: Both html (mixed with Template Toolkit), and those normally intended to be processed by Catalyst. I am aware of Catalyst::Plugin::Static::Simple, but that doesn't seem like it does what I am describing since it simply prints files statically.
As an example, I want to show whether the user is logged in on index.html without using ajax or SSI. There are many other cases beside that one.
There is probably a simple answer to this...
Thanks for the pointer, RET. My solution turned out to be pretty simple.
I made the nginx config point to my Catalyst App before serving files directly and added the path to my html files to the TT config in myapp.pm.
Here are the basics of the snippet I added to my Root.pm controller in the default subroutine:
if($c->req->path =~ m{\.html$} || $c->req->path =~ m{\.htm$}) {
$c->stash->{template} = $c->req->path;
$c->detach;
}
elsif($c->req->path !~ m{[.]+}) {
$c->stash->{template} = $c->req->path . '/index.html';
$c->detach;
}
The good news:
I don't care if it uses ajax or not.
I don't care if the user must install a specific browser to make it work.
I don't care if there isn't any specifc progress bar.
The bad news:
I don't want to use flash.
The user must upload a file from any width or height - however no bigger then 8MB.
The file must be stored on a specific folder (or database column).
A thumbnail must be generated on a specific folder (or database column).
Those images must be associated with a specific record.
This is a "modus operandi" question, I realise that there is to much code involved here.
So:
We first create our form element to support multiple upload, like this:
$element = new Zend_Form_Element_File('multifile');
$element->setAttrib('multiple', true);
$element->setIsArray(true);
We then, need to add some validations and allowed extensions;
Then we need to process the upload;
Once the upload is done, we need to resize those multiple files according to our needs.
We need to store those resized files somewhere else.
Once all this is done, we are ready to display the files associated with a specific database record?
Is this the way to go? Should I have more steps? Am I missing something. I've never done this before, but I'm taking it like a challenge.
First, you create a form. Not much complication here:
$this->addElement('File','Filedata');
$this->Filedata
->setLabel('Select images')
->setDestination('somepath') //define & create it somewhere earlier ;)
->addValidator('Size', false, 1024000)
->addValidator('Extension', false, 'jpg,png,gif')
->setMultiFile(5)
->addValidator('Count', false, array('min'=>0,'max' => 5))
;
In the controller, you receive the images. They will have temporary random names, which you can keep later if you wish (I usually do).
$fileinfo = $form->Filedata->getFileInfo();
$path = 'somepath'; //make sure it exists
for($i=0;$i<5;$i++) {
if($fileinfo['Filedata_'.$i.'_']['tmp_name']) {
$img = new Imagick($fileinfo['Filedata_'.$i.'_']['tmp_name']);
// image processing goes here
file_put_contents('somepath',$img);
}
}
And that's it ;)