Merging two Images with CodeIgniter Image Manipulation Class - php

I am developing a new project in CodeIgniter (CI), and would like to find a CI solution to this current issue. I've got one image, which resembles a picture frame. I would like for uploaded images to be modified to have this frame in their background.
Example:
alt text http://www.sampsonresume.com/projects/visit-creation/vc-process.jpg
The first picture is the frame. The second is the uploaded image (after resizing/cropping), and the third is the combination of both, which I would like to accomplish.

If the images are going to be shown on your own website, it would probably be easier to simply use CSS (especially if your bottom image simply gives a border...). Of course, if you want people to be downloading these files with the frame, that's a different story.
I don't think CI has a built in method in the Image Manipulation class. But, that class is simply abstracts typically-used features from one of the three major PHP image libraries (GD, ImageMagick, and NetPBM). If you know what library you are using (I normally use GD for basic things like this...), then you'll just have to use their proprietary ways of doing this stuff.
You can even make your own library or extend the Image Manipulation class to add your own special features.
Also, there may be ways to do this in Zend (not sure, I'm not going to look it up either). But, there are easy ways to include Zend components into CI if you do find something.
Good luck man!

Agreed with Kyle -- your best bet is to extend the libraries already there. Take a look at ImageMagick "composite" command.
composite -gravity center smile.gif rose: rose-over.png
http://www.imagemagick.org/script/composite.php

Related

Adding and removing watermarks from PDFs

We want to add our company's watermark to pdf files (that are uploaded by users).
We found a couple PHP libraries for manipulating PDFs. We're currently using FPDF. It appears fairly straight-forward to add the watermark, but we're struggling to figure out how to remove it.
Is this a limitation of this library? Or is there a more general issue with PDFs that makes this difficult?
I used for basic manipulation FPDF, but once I tried a little bit the java itext library it's pretty awesome. And really I recommend to you further reading iText in action. Just give a try through the vogella tutorial. The time you take for this will be really improve yourself.
Specially you can use the PdfStamper for this purpose. I can share a basic usage in https://github.com/web20opensource/stamper
In something similar way like adding a new layer to a image, it's the same way for manipulation pdfs.... you're adding a new layer. And as the same happens in images you can't remove a layer after you have merged all the layers.

How should I generate an isometric image of a Minecraft skin in PHP?

I'm trying to generate 3D isometric views of players' heads, but I'm not sure what kind of support PHP has for this type of operation, or of any external libraries that may be better suited.
Basically I need to take a net like this (here is a diagram showing what each portion is mapped to) and make a 3D head from it. I also need to include the 'head accessory' portions, which should be slightly larger/offset from the actual head.
Does anyone know how I should go about this?
Well first it will be a complex job in my view.
The http://www.minecraftwiki.net/images/0/01/Skinzones.png file you mentioned is flat, but you have to convert that in ISOMETRIC 3D look, so you have to distort the images
For example look at the images below
So you can see that 3D box image is created from the pieces of other images, the logic is to add perspective to the flat images and join them. but as it is 2D we will call it Image Distortion.
Unfortunately GD Library which comes bundled with PHP is not advanced enough to let you do such things.
You have to use some other library like Image Magic and this link is tutorial for using distort functions http://www.imagemagick.org/Usage/distorts/
Second big thing is the processing of the images, you can process the images live but it will consume lots of resources on server, so it is suggested that you use pre processed images, and not process them every time.
To generate the Isometric image you have to write the code your self, and it may need alteration on each image character depending upon the size of the image. But when you have written a code it will be easy.
My Suggestion is to write your own code once, then alter it for every character and save the processed images in a sprite and use them when you add play functionality.
check out this link as well
http://www.fmwconcepts.com/imagemagick/index.php

Getting PDF color in PHP

I am trying to make project of a web app that will check the colour of the PDF document. My preferred language is PHP.
At the begining I've been thinking about GD, but this only refer to images (jpg, png, gif). Nothing for PDF. For images I am going to use some method similar to this: Get image color.
So does anyone know some method, library (opensource), or something else to make such app? I can't find any examples on the web.
You'll probably be best off converting the PDF into an image, and then using the same method you're using for images. In addition to being easy to do, that will also guarantee consistent results.
However, converting a PDF file to an image is not something that PHP alone is well-equipped to do. The best way to go is the ImageMagick based approach as described in this question. It gives a number of alternatives, too.

In CakePHP, whats the best Image Upload / Resizing component you've used?

Im looking for somthing that can belong to many many models and, hopfully, has all the resizing functionality built in too.
Wondering if there's any good suggestions out there, I don't want to pick the wrong one.
Or is it just worth building my own?
I wrote a pretty sweet image upload component a few years ago for Cake 1. I don't have a clue where the code is these days, but my friend Koa did a write up on it a while back:
http://labs.iamkoa.net/2007/10/23/image-upload-component-cakephp/
http://labs.iamkoa.net/2007/11/06/multiple-image-uploads-into-single-mysql-table-cakephp/
Might be something you can hack. It handles uploads, resizing (resize, crop, resize then crop, max, mix) and if I remember correctly, it might even do filters (flipping, inverse, greyscale).
I also ported the code to Zend framework (and PEAR file naming) for my new content management framework. It's all contained and much better now (does all the things I mentioned above and is pretty well documented). You can download that here (check out the ImageManipulator class. I think the FileUploader class has a dependency on my String utils class which you could easily remove if you want to use that.
Otherwise, I say roll your own. The component architecture in Cake was confusing to me at first so it could be a good learning XP if you don't know it yet. If you do, you can just grab someones uploader and convert it into a component for your Cake application.
Check out the Media plugin by #nperson https://github.com/davidpersson/media/wiki
https://thoughtwm.com/code/ for the image upload
&
http://www.darrenhoyt.com/2008/04/02/timthumb-php-script-released/ for the image resizing
How about for getting EXIF/Meta info of the image?

What are best practices for determining if I should create a new Drupal module?

I'm using Drupal for the first time for a project at work. I'm finally getting my head wrapped around some of the core concepts, but when it comes to customizing output I'm unsure of how to proceed.
I have to build a fairly specialized image gallery. I've managed to cobble something workable together using Views2, but it's not quite where it needs to be. I'd like to write it from scratch, using SQL and actual PHP, rather than working through this web UI.
I figure I'll put this functionality in a new module. Is that right? Or is that an abomination to the Drupal world?
Edit:
Here's what I've got so far. I've created Image Gallery and Image content types with CCK. Images can be assigned to multiple galleries, via nodereference. I've got imagecache creating two sizes for each uploaded image - a thumbnail size and a gallery size.
Two gallery formats are required, but let's assume I'm going to have a carousel style for now, with some custom JQuery and CSS to match the rest of the site's look and feel. Clicking a thumb in the carousel-style navigator will load the full sized image above it.
Now, assuming such a thing does not exist, what is the recommended approach for creating it? Not how to code it, but where would this code live within the Drupal system?
It seems like views will do the job of creating the data you need - a list of all the images for the galleries, based on whatever criteria you need (taxonomy,author or whatever) and that the carousel part - adding the jquery and css could be done by using drupal's themeing system to change the output.
So as ar as 'where would the code live' I would say in your theme, rather than a module.
The views theming system is pretty comprehensive, if possibly a little overwhelming at first.
This looks like a good starting reference: http://www.group42.ca/theming_views_2_the_basics
You can do this. Views is great but will often only get you 90% of what you need out of the box.
You can do views theming, which can take you further, and you can write extentions to the views functionality (but that is not always easy).
There is nothing wrong with writing your own module in stead of views, in some cases it can increase performance. One tip if you are doing this is that you can see use the query that views creates in your custom module, this can save you having to work it out and write it yourself.
Yep, I'd put this in a module. I often wind up writing custom ones for specialised use cases.
Well since it is free software you are free to do (almost) whatever you want with it.
A good practice to decide if you should do it is:
Will the benefits that I will get from
a custom module divided by the time
I'm going to invest in it. Outweigh
the benefits / over time of a solution
that isn't ideal?
Or if you prefer to look it this way:
Custom Development Benefits Not 'ideal' solution benefits
--------------------------- > -----------------------------------
Development Time Time to install and adapt
Since normally the Time to install and adapt normally is smaller than the time to develop something from scratch, the common conclusion is to just use what is already there.
But by all means if you want to develop your own thing and have enough time, go ahead.

Categories