Using Timthumb to Resize Images from CKEditor - php

I am using CKEditor to do basic text and image input into my website. I have noticed that it is quite sporadic in it's method of generating HTML for images when you add them. (Sometimes it might use height and width tags, other times it might use CSS).
I use Timthumb for on the fly image resizing on a number of other websites and find it very useful. I use a mod_rewrite rule in my .htaccess file to allow me to create domains like http://localhost/images/800x600/image.jpg and achieve resizing.
I would like to somehow incorporate this into CKEditor. I cannot find how to do this looking through the documentation so I have tried post-processing the data produced by CKEditor using Regex, however as mentioned before CKEditor seems to be too sporadic to be able to get this to work all the time.
Anyone else done this before? How did you achieve it?

I've done this in Grails. It's quite painful because of the random usage of html attributes and css. I ended up using an html parser, iterating over the images (dom nodes) and resizing those who has been resized. After that the html attributes and/or css styles has to be updated. It took quite some time to get it right as there are so many things that can go wrong.

Related

SVG image get's messed up when I put it into html

I have been starting using SVG recently and I love it. There so clean, cool and easy to design.
Well I stumbled across a issue when I tried to one of my svg's into html (Works with every one of my svgs except this one). It works totally fine if I call it as a image (<img src="hill.svg"></img>) but when I try to use it
either with PHP(include 'hill.svg';) or just straight up passing it in on the index files, it messes up.
Here's an image. Messed up svg top left and the working on the full screen. Same file just that the working one is imbedded with "background-image"
It kinds of look like the background is turnt into one of those "missing- image-icons"
Any help would be highly appreciated.
Svg: https://pastebin.com/RsSAGv8M
There are some raster images linked in your SVG:
947B2F3D9DDD76B8.png (two times),
947B2F3D9DDD76B9.png,
947B2F3D9DDD76BF.png
They are probably not available on your webserver. If the SVG is linked as an <img>, they are never tried to retrieve, as for security reasons all images must be self-contained. But when the SVG is embeded in a HTML page, the request fails. and some browsers show a "missing image" icon.
Either delete the <image> tags in your SVG file (it seems you did not miss their content?), or embed them as data URLs. (I don't know Adobe illustrator good enough to know if there is a utility to do that.)

html2pdf embed SVG files

I'm trying to use html2pdf to automatically create brochures that may need to go to print so need certain elements to be vector based. The class is hopelessly documented and I've got stuck trying to embed SVGs.
If I just try to embed the SVGs in the HTML to output like <embed src="img/test.svg" type="image/svg+xml" /> then I get an error saying the necessary methods to use this tag don't yet exist, likewise for <object> tags.
Digging further and the examples seem to show some sort of, I assume, proprietary <draw> tags that consist of all the required co-ords to draw the SVG. However I can't find any documentation anywhere to explain how to generate these?
Has anyone ever successfully embedded a SVG into a PDF using html2pdf?
Well I've partly figured this out, it seems the <draw> tag just contains the contents of an SVG file ("show SVG code" when saving as SVG from Illustrator) but it turns out html2pdf doesn't support bezier curves, which makes it pretty much useless for most things.

Export div content to image

Currently I'm working on a project in which user of website can design a giftwall by drag and drop of gifts. Drag, drop and sorting works perfect and I'm able to store generated giftwall into database. On recipient side system lists all the gift images in the same sequence sender sent so it visually looks like a giftwall. I want to allow users to store this giftwall into a single image so they can store their giftwalls into image album. In current system it lists all individual gifts into a individual div resided in main wrapper div. How can I export this wrapper div to image so it looks same as HTML. Any help will really be appreciated. Waiting for reply.
Thanks!
I don't know if there is a way by using pure javascript, but you can generate the image on your server and send it back.
I have never heard of saving browser's viewport to an image file via JS. I think it's only possible vie creating SVG or using HTML5 canvas.
I asked exactly the same thing a while back.
HTML div to screenshot?
The conclusion is... it is not possible with JS. Questionably possible from PHP also.
Use can use an online service for screen capture, like browsershots, but its not in real-time, and doesn't render everything well.
I used a workaround for my situation.
Recreated all the DOM/HTML elements which create the image (load parameters form database, and generate the DOM). Wrap everything in one container div, and zoom it out to the size you need.
I know, not the prettiest solution, but the only solution I could get to work.
Using <canvas> you can create image that will looks similar to how it looks on the page. Try it this way:
Get the size of wrapper <div> and create the same canvas element. Then get the position of each image in the div wrapper and draw that image on canvas at the same position with the same size.
Things may be harder if you need to draw additional controls, like button or textbox.
All modern desktop browsers suport <canvas> now.
You can either use html2canvas, which isn't perfect yet. Or store browser offsets of elements in div and then with GD or ImageMagick combine them into an image
Maybe this could be of use: http://html2canvas.hertzen.com/

dynamically scan pictures in a folder and display using jquery slideshow

anyone know how to scan a folder using jquery or javascript code snippet, after that get a picture file name and embed in <li></li> or <div></div>, i've used php code to read through the folder and loop through the element to display the thumbnails and all, but it's not work well.
I've try on galleria, gallerific, galleryView jquery slideshow plugin but those might not work well with php processing because of predefined configuration or something, can anyone tweak or hack these gallery to dynamically read an image from a folder?
There is a way to read local files using javascript, but it requires the user to set up his browser appropriately. I know about such feature in Firefox. In your case, the best way would be to use PHP for folder scan and Lightbox for image display (which in turn has slideshow plugins).
Perhaps you'd be better of saying what didn't work well when you tried the PHP path and we can help you fix that?
Your best bet is probably going to either be an existing thing such as Gallery as powtac mentioned, or if you are only wanting to display images from a single folder that might be a bit of overkill.
You could use PHP to output the thumbnails and whatever other information you need into a list of <li> tags, use CSS to hide some of them (if required) and then use Lightbox or any of the many other JS image galleries available to do what you want.
Then you can ask on here if you are having trouble with one of those steps (detailing what you are doing, what's going wrong etc).

Using PHP to recreate something similar to VistaPrint / CafePress / Zazzle. Any Ideas?

I am working on a website in which the client wishes to have users upload background images to a printable design, crop to size, add text. Do this to multiple pages then generate a pdf of the 'book'
I am running into the following issues/questions and just need to see where I can start
Are there any PHP developer packages that can do something similar. I have seen jquery crop tools but something also for adding text to an image?
How would I keep the resolution up? If the final cropped with text image needs to be 150dpi, when cropping I am guessing I would have them working on a 72dpi image, then somehow apply the crop and changes to the large image?
If the resolution issue wasn't a big deal I would go about it this way:
Simple image upload
Use jquery to crop photo to correct dimensions
Mess around with gdlibrary and imagettftext() to get the text onto an image (page)
Use something like FPDF to create a pdf from each 'page'
Is this the right way to go about it and any thoughts on the resolution issue. Thank you for any help!
Your primary tool should be ImageMagick. ImageMagick can do the cropping, resizing, scaling, overlay text or graphics, combining images, and apply special effects. A big advantage of using a separate tool instead of PHP's image manipulation tools is that you can do the same transforms in batch through other mechanisms, or even hand the work over to another server to keep the website more responsive. And if you do want to integrate it tightly into the website, you can use the MagickWand For PHP interface.
Cropping does not change DPI, only the dimensions of the image. Scaling, on the other hand, changed both.
You should take a look at Gallery, a GPLed program with some of the functionality you're looking for, and written in PHP.
domPDF is a good tool for converting HTML to a PDF. this way you can use the image they upload as a background image, then put the text over it in any standard HTML tag.
As far as the resolution/dpi issue goes, I'm not sure if there is much you can do outside of changing the size of the image. I would recommend looking into This PHP Library, which has a lot of good tools for manipulating images.
I think with a combination of these tools, you'll be able to create HTML that can make a PDF that's fit to print, and use that.

Categories