Comments (18)
Have you tried the fill
method?
from simpleimage.
Yeah. That will fill entire image into white, ie. there would remain no image, just the color
from simpleimage.
Can you create the background image using fill
and then overlay
it with the PNG?
from simpleimage.
Also would be great if you can tell me how can I use box_crop in SimpleImage.
First adaptive_resize or best_fit to fit within size. and then put that in a box of the required size centered.
For example, a facebook profile photo. I want to adaptive resize the photo, but don't want to leave it with it's own dimensions, but fixed dimenstions, say 180x180.
Hope you understood the situation. lemme know if I need to explain further.
from simpleimage.
Adaptive resize should be all you need:
This function attempts to get the image to as close to the provided dimensions as possible, and then crops the remaining overflow (from the center) to get the image to be the size specified
Let me know if the fill/overlay solution works.
from simpleimage.
- Fill with overlay should work. but fill won't work without an image. Ofcourse can do by manual coding, but with SimpleImage.php, u can't create an empty image with some bg that you can overlay with.
- I did try adaptive_resize assuming it the same, but it won't work. it instead crops image after a point.
Screendump http://i.imgur.com/CwKoE2B.png
from simpleimage.
Actually, just use create
:
$img = new SimpleImage();
$img->create(100, 100, '#0088cc')->overlay('overlay.png')->save('result.png');
I just tested this using overlay.png
in the example directory and it works fine. (You could also have used fill, but you'd need to do it on an existing image.)
For adaptive resize, it will resize the image as close as possible and then trim (crop) the edges. I'm not sure why your image obtained a black background...just tried with a similar PNG and it resized it with transparency:
$img = new SimpleImage();
$img->load('firefox.png')->adaptive_resize(50, 50)->save('result.png');
Closing this since the original issue is resolved.
from simpleimage.
Ok. You can close.
But that won't work still.
- overlay excepts image path. So even if you try to save the uploaded image (which has turned black background), it makes no sense. plus one cannot use the temporary uploaded image ($_FILE['file']['tmp..']) as a parm for overlay()
- adaptive_resize won't work. Do try this image https://upload.wikimedia.org/wikipedia/commons/6/6d/Mozilla_Firefox_logo.png
:)
from simpleimage.
For #1, look at the example again. It's creating a filled image from scratch, then overlaying overlay.png
on top, and saving it as result.png
. Using that image as an example (filename changed for my own sanity):
$img = new SimpleImage();
$img->create(500, 500, '#0088cc')->overlay('firefox.png')->save('result.png');
Results in this image:
one cannot use the temporary uploaded image ($_FILE['file']['tmp..']) as a parm for overlay()
I'm using many methods on files that are uploaded—they are in a temp directory so you should be able to read/write to them. Maybe talk to your host about why you can't read/write to the system temp directory, or try using tempname()
to create a file that you'll be able to read/write to. This issue is really outside the scope of the library.
For #2, using the same code and your image:
$img = new SimpleImage();
$img->load('firefox.png')->adaptive_resize(50, 50)->save('result.png');
Here is the resulting image:
from simpleimage.
#1 is okay. my bad. I was passing the simple's $img object ;)
#2, try a size like adaptive_resize(500, 250)
How it should be -> http://i.imgur.com/IWHBSbP.png
How it is http://i.imgur.com/L6tLqbB.png
And thanks for the help on #1 :)
from simpleimage.
#2 though it can be solved by, again, using a pseudo image and overlapping it with actual image using best_fit.
from simpleimage.
I'll have to take a closer look at adaptive_resize
...I didn't write that method so I'm not sure if that's the intended behavior or not. If I remember correctly, it replaced two other methods—one of them being square_crop()
which is what I think you really need here.
I don't have time today, but hopefully by this weekend I'll be able to address this. You should be able to find square_crop
in the commit history if you want to try it out. Chances are, if adaptive_resize
is behaving as expected, I'll add square_crop
back. Otherwise, I'll just fix adaptive_resize
so it works properly.
Ultimately, we need to document exactly what behavior adaptive_resize
has on portrait, landscape, and square-shaped images and then make sure it's doing that.
Reopening under a different title.
from simpleimage.
#Appreciate.
Also, would suggest to add the png-background func in your class.
Am adding in mine, but if you add it directly in your class, would help ppl save some lines of code for each image.
#Logic
function fillBackground($color=#fff,$width,$height){
if(!$width) $width = $this->get_width; // same width of the image loaded in the instance
if(!$height) $width = $this->get_width; // same width of the image loaded in the instance
// Create and overlay code
....
}
from simpleimage.
It turns out adaptive_resize
is working correctly according to the comments:
This function attempts to get the image to as close to the provided dimensions as possible, and then crops the remaining overflow (from the center) to get the image to be the size specified.
However, I'm wondering what use cases exist for this behavior. It seems to me that the resulting image should be scaled to fit inside the new dimensions (like you suggest) instead of being cropped.
@nazar-pc - do you have any thoughts about why adaptive_resize
works this way? (re: this comment)
from simpleimage.
adaptive_resize
works such way to be used in thumbnails. Usually, thumbnails have some specific dimentions, and it is better to crop something, than to leave empty space.
Probably, adaptive_resize
can be renamed to adaptive_crop
, and to add adaptive_resize
with additional parameter of color for filling empty space.
from simpleimage.
Makes sense...unfortunately that introduces an API change and would mean we'd have to bump to 3.0. Instead, let's deprecate adaptive_resize()
and re-introduce the same functionality under a different name—perhaps thumbnail()
. adaptive_resize()
will remain intact until 3.0, per SemVer. It will simply become an alias of thumbnail()
until then.
I think best_fit
can have an optional third argument that will maintain the specified size, which would be a useful additional and will solve @scazzy's case.
I'll post an update shortly.
from simpleimage.
Didn't get time to add the new best_fit()
argument, but you can probably get by with using create()
and overlay()
for now. Feel free to contribute a patch if you'd like :)
from simpleimage.
Cool. sounds great to add thumbnail()
method.
Yeah I saw changes for the create()
method. Thanks. I'll try to make a workaround until then using this.
from simpleimage.
Related Issues (20)
- A feature to fit image in a fixed canvas size with blur background of original image. HOT 2
- Auto fit in square and use source image as background.
- resize function does not check size values HOT 2
- Can not add a text on image HOT 2
- PNG to JPG is possible to change transparent background color? HOT 2
- Background color for text HOT 7
- How to different font file & size, but in an equal position with center align HOT 3
- PHP 8.2: Deprecation warning "Creation of dynamic property"
- Implicit conversion from float 50.800000000000004 to int loses precision HOT 2
- Imagick magick support HOT 1
- Bump `thephpleague/color-extractor` to 0.4 in composer.json HOT 1
- Nothing working HOT 1
- Implicit conversion from float to int loses precision HOT 3
- QR Code HOT 1
- getExif(): Return value must be of type ?array, bool returned HOT 1
- Images not destroyed? HOT 1
- Set fixed size for overlay image
- Request: Combine two pictures
- Implicit conversion from float 56.25 to int loses precision HOT 1
- PHP E_WARNING when imagecreatefromstring() is used
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simpleimage.