Home » PHP » PHP Tutorial: Creating A MemeGenerator / Cheezburger Clone - Part 4

PHP Tutorial: Creating A MemeGenerator / Cheezburger Clone - Part 4

Part IV: Signing And Saving Your Masterpiece

In part 3 of this tutorial, I showed you how to make your text fit and wrap it if necessary. Now all we need to do is add your site signature and save the file to disk.

Why save the file to disk when the user can easily just right click on it and save it? Well, if you're going to offer a gallery of images or any other service where people can view it again, delivering a static file from disk uses a lot less server than generating the file dynamically every time.

Saving is this simple...

$img->setImageFormat('jpeg');
$img->setImageCompressionQuality(70);
$img->writeImage('path/to/your/photo.jpg');

Set the format.

For a JPEG, you should set the compression ratio (I've found 70 to be a good mix of size savings and good image quality).

And write the file to whatever new place and name you're giving it.

This is an image with the user caption and the site label, saved to a static file.

But you see the lovely label at the bottom? How did we add that black stripe and that text?

Well, the text you should know how to do by now. The black stripe, however comes from two more lines...

$img->setImageBackgroundColor($strokepixel);
$img->extentImage($imgSize['width'],($imgSize['height']+20),0,0);

With the first we set the stripe color to the same color we used for the stroke... black. If you're letting users choose colors, you might want to hard code it to your preferred stripe color.

Earlier on, I used $imgSize = $img->getImageGeometry(); to get the size of the photo. Now I extend it with extentImage(), using the same width, the height plus 20, and I set top left of the original image at 0,0 so the image is at the top.

Then I can use the drawing functions for text that we've been exploring to add my label with a thinner font in a smaller size.

And that's it. You now have the basics of how to create a clone of MemeGenerator or the Cheezburger sites.

Tags: ,

9 Responses to PHP Tutorial: Creating A MemeGenerator / Cheezburger Clone - Part 4

  1. I absolutely love this. Is there any chance on getting the full code for the final product?

    Thanks, Jereme

    • Jereme,

      Don't know what you mean by "final product". If you mean the whole site when PicScribbler goes live, including the image captioner and all the supporting functionality, probably not.

      For just a script to generate images, you should be able to generate one yourself by going through the series of posts.

      • Yeah I just meant the demo that you have with the input and sumbit button to update the image. Not wanting to take your entire site. :)

        I really like what you have put together here and really appreciate you sharing it.

        I have just finished putting together something fun that the guys at work wanted me to do.

        jerememe.com

        Thanks, Jereme

  2. Thanks for the tutorial!! Check out what I put together.

    http://jerememe.com

    • Jereme, do you have the source for your preview.jpg available? I have been having trouble getting the bottom text to work right and I could use an example.

  3. I just noticed but the link to this blog at http://www.picscribbler.com is broken. Figured you would want to know.

    Thanks, Jereme

  4. Hi,

    Can you make the script downloadable?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>