I've been running a site where users can upload and crop photos of themselves and the enforced image shape was a rectangle.
Lately, I've been developing the new version of the site, and the image shape I'm now using is square.
I might have around 30,000+ images, and I want to move them from the old site to the new, but I need to convert them from rectangles to squares:
Is there a way to to do this conversion without losing parts of the image (eg: without cutting off part of it) and without distorting the image eg: it becomes squished and doesn't look like it should?
The images are of people's faces.
Any advice on a conversion like this? I'm good with PHP, so maybe I can script a job to do the entire conversion. I just need to be able to convert one image successfully.
Related
I've been struggling with getting what is possibly a quite simple bit of code working and as a last resort, I'm reaching out for help!
The basic goal is to layer 2 pngs and output them to the browser without saving them to disk. The difficulty comes as I want to recolour the layered image on the fly to the users preference. From all of the posts on here (thanks guys) and other sites, I've managed to get it working to a level, however not without saving the image.
Here is the background image (in this case a t-shirt)
enter image description here
and here is the layer (a transparent 1, coloured black)
enter image description here
Overview:
I am working on a video creation project. The technology I am using are: imageMagick, php, ffmpeg.
Current Status:
Currently the project is able to create videos using images and texts and few basic transitions. The way I am doing it is using imagemagick to create gif using input images(with transition effects in them) and then converting all gifs to videos and atlast concatenating the video together.
Next Move (My question):
I am now set to take it to the next level. So, what I am having is a video(1920x1080) with some white frames(1280x720) that keeps shifting in each frame. I want to replace those white frames appearing in some frames of the video with some images(1280x720) that I wish to use. Please see the image here and you will get an idea: These are just two frames from my video. If you can see carefully the images are shifting(white space is not constant).
Expectation:
So, I want to fill those white space with one of my own image. If the case would have been for only one frame I could have used ffmpeg to overlay image on the exact width and height. But here the white space is not fixed and keeps shifting in all the frames and there are a lot of frames. So, I am looking for something like opencv or some other technology that can be used for object detection in a video or in a set of frames and replace the detected area with some other image.
I just need a kick. So, if anyone has already worked on something like this just suggest me what technology can I use. Thanks in advance.
It all depends on exactly what you can assume :
If you can safely assume that your rectangle's boundary is never occluded (hidden) somehow, you can try finding the edges in your image (like OpenCV's Canny edge) and then look for rectangular shape (corners forming a warped rectangle, or the very popular Hough Lines).
If the rectangle you're looking for is always white, you can threshold the image in a colorspace like HSV to look for maximum value (the V in HSV ~ brightness) then rectangular shape search in a binary image.
If your corners are occluded sometimes you'll have to do some tweaking with your image, like morphological operations ("grow and contract" binary thresholded image), then Hough Lines could do the trick.
Note that this answer assumes that once you know where the rectangle is, "you're done", and you just have to overwrite the rectangle with custom content.
I also do not check for any time-continuity : you video frame might jump around based on the frame-by-frame appearance of rectangle. You'd have to include some knowledge about previous positions.
We have a custom built CMS which allows for image uploads. In the CMS we have implemented
jCrop. When cropping an image (with GD in PHP), we are storing the original image name and crop image name in the database (MySQL), aswel as the original image and crop image on the server.
When we need an alternate crop, we use PHP to create another crop of the cropped image (and save it to the server). Because such an image has now been processed by GD twice, the result often looks bad.
A possible use case: in the CMS we manage persons. Each person can have an image. Since persons are usually shown in portrait mode, we let the user crop in portrait. On the website this works out fine, but on the mobile website, we actually need a square image. Hence we need two crops.
Lately we've been wondering how we could improve our crop workflow. Would an approach of only storing crop coordinates in the database work on the long term? What is a common approach of dealing with crops?
Thanks in advance!
I would use this approach:
Upload an image. Assign it an unique ID (i.e. an MD5 hash of the name).
Let the user crop it, store only the coordinates and image name in the db
Store the cropped image, give it a filename that is made for example out of the original file name plus the coordinates of the crop.
In this way you will be able to retrieve the cropped image only by knowing it's original name and the coordinates of the crop. In addition an exact duplicate of any crop would not be stored.
Example:
md5('image.jpg' . $crop->x0 . $crop->x1 . $crop->y0 . $crop->y1);
Would an approach of only storing crop coordinates in the database work on the long term?
Not if by that you mean you would also do the cropping each time the picture is requested. That puts unnecessary load on both your server (doing the actual cropping on-the-fly each time) and on the client as well (because there will be no caching of those dynamically generated crop images, unless you implement that on top of the whole thing).
Since persons are usually shown in portrait mode, we let the user crop in portrait. On the website this works out fine, but on the mobile website, we actually need a square image. Hence we need two crops.
Maybe a better approach would be what f.e. Facebook does in some places: Instead of cropping an image to be square server-side, the just have the client load the non-square version – and then let the client do the “cropping” by simply displaying the image as a positioned background image within a square element …
I'm trying to make a simple app which gives a user a standard background/template image onto which they can place their logo/brand/whatever. I've had a look at a few jQuery plugins which allows the user to upload and crop an image, and most of them seem to work by posting the x and y coords, and the width and height, to the server.
I'm able to then use imagecopyresampled() to merge the image with the background image, but (a) the user's image seems to end up really skewed, even when I hard-code dimensions that I know should work, and (b) I need to position the uploaded image pretty much dead-center -- what's the best way to achieve this?
Any help? This is my first time using GD. I'll add my own code if required, but I'm messing with the different GD functions, so I've butchered the one I had before. Will reproduce it.
Thanks
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.