mercredi 1 avril 2015

Watermarking regardless of resolution

I'm having a problem with applying a watermark to uploaded images, the main problem is the image resolution since my watermark image has a 30dpi resolution while uploaded images ranges 30 ~ 300 dpi resolution, so the watermark is not of the correct size respect the image (too small / too big) and i'm unable to find a math formula to resize it correctly.



float offest = imgU.HoriziontalResolution / imgW.HoriziontalResolution


this is where i start to elaborate the proportion between the two images, the first is the uploaded image while the second in my watermark. My watermark is 120x20 and 30dpi while the uploaded images ranged between 300x50 and 30 ~ 300 dpi in size.


I also have the problem to correctly align my watermark to the bottol left corner since of the different proportion that doesnt allow me to correctly calculate the y offets to place it at.


How to get the names of files present in tags from a string and create an array of all those file names in PHP? [duplicate]


This question already has an answer here:




I've one sample string as follows :



$feed_status = Nice to see you all back again <img src=\"http://ift.tt/1BZQwnH\" alt=\"Smile\" title=\"Smile\" title=\"v_middle\" /><img src=\"http://ift.tt/1BZQwnH\" alt=\"Smile\" title=\"Smile\" title=\"v_middle\" /><img src=\"http://ift.tt/1BZQwnH\" alt=\"Smile\" title=\"Smile\" title=\"v_middle\" />;


(Forgive me for syntactical errors like placing of single quotes and double quotes)


For your reference I've just added three <img> tags to the string but in real situation ths string could contain a single <img> tag or no <img> tag or more than one <img> tags.


I want to get names of files present in each of the <img> tag's src attribute and make array of those file names.


In this case the resultant array should be as follows :



$new_arr = {smile.png, smile.png, smile.png};


How should I do this in an optimum way using PHP?


Thanks in advance.


What would be the best size for a full-width website slider image?

I have a client who needs a slider to be full-width, without any containers or wrappers. I think it's bad practice(you may correct me otherwise), but I couldn't convince her otherwise. I'm concerned about the image sizes. The images are lazy-loaded, but still. One image can take a long time to download if I set it to be too large.


airbnb does it quite well here: http://ift.tt/1DoJOPp


What should the maximum width of the images be?


WPF Image RenderOptions.BitmapScalingMode.LowQuality consumes 10x more memory than HighQuality

I have an image which is about 5k x 5k pixels.

The image contains a LayoutTransform with a ScaleTransform.



<Image x:Name="image" Source="{Binding ImageSource, Mode=OneWay}" Width="{Binding ImageWidth, Mode=OneWay}" Height="{Binding ImageHeight, Mode=OneWay}" Visibility="{Binding ImageVisibility, Mode=OneWay}" RenderOptions.BitmapScalingMode="HighQuality" RenderOptions.EdgeMode="Aliased">
<Image.LayoutTransform>
<ScaleTransform ScaleX="{Binding ScaleValue, Mode=OneWay}" ScaleY="{Binding ScaleValue, Mode=OneWay}"/>
</Image.LayoutTransform>
</Image>


Since scaling the image is very slow due to the HighQuality option, I decided to set it to LowQuality during the scaling process. As it turns out the LowQuality option consumes much more memory than HighQuality as you can see in the screenshot.



RenderOptions.SetBitmapScalingMode(image, BitmapScalingMode.LowQuality); //Reduce quality during resize to improve performance (or not :()




The memory peak after setting it to Low is not temporary - it stays until the application is closed. A second or third resize operation has no effect on the peak.



I believe the Image Control caches the image of some sort - not sure though.

I am also familliar with a memory leak which can happen if a BitmapImage is not manually destroyed but I think this is not the problem here since the peak happens during the RenderOption-change.



Any ideas are very much appreciated enter image description here


Define 2 plotted lines in an image as variables inside a function in Matlab?


Function [Yupper, Ylower] = Segmentation(A)
A=imread('g16.BMP');
AR=A(:,:,1);
[rows, columns] = size(AR);
avgs = mean(AR(50:165,:), 2);
avgs2 = mean(AR(165:315,:), 2);
[~,ind]= max(abs(diff(avgs)));
[~,ind2]= max(abs(diff(avgs2)));
figure, image(AR,'CDataMapping','scaled'); colormap('gray'); hold on;
Yupper=plot([1 size(AR,2)], [ind+50 ind+50], 'r', 'LineWidth', 2);
Ylower=plot([1 size(AR,2)], [ind2+165 ind2+165], 'g', 'LineWidth', 2);
end


Above is code used to segment grey scale images based on large instensity changes,I'm looking to declare the 2 plotted lines as variables so I can carry out future processing. However, If I type in whos , the lines appear as follows in the table;



YL 1x1 112 matlab.graphics.chart.primitive.Line
YU 1x1 112 matlab.graphics.chart.primitive.Line


if I remove the the plot commands I receive errors associated with brackets etc and if I manipulate the code any further it seems to mess up the correctly plotted data, can anyone help?


PHP rotate issue for uploaded image and copy same image with same resolution

I have an issue for image rotation. There are two step process 1) Upload 2) Crop. On the 1st Step when I am uploading image I am moving using following script.



<?php
........
$output_dir = "uploads/";
$fileName = time() . rand();
$upload = $output_dir.$fileName;
move_uploaded_file($_FILES["myfile"]["tmp_name"],$upload);
setcookie("upload", $upload, time()+3600);
....
....
?>


Note : Assuming the image uploaded is with .jpg extension.


After above code execution it generates a file like 14278875238271 which contains high resolution image object and 14278875238271.jpg which is low resolution image.


Now once this image is uploaded moving to next step crop page..... This page shows low resolution image 14278875238271.jpg to crop in circle format, now if anyone want to rotate image there is button to rotate left / right and on clicking on that button I am executing the following function code.



function rotateImage($sourceFile,$angle=0){
$imageinfo=getimagesize($sourceFile);
$bgColour = 0xFFFFFF;
/*---For low resolution image ----*/
$original = imagecreatefromjpeg($sourceFile);
$rotated = imagerotate($original, $angle, $bgColour);
$rotated = imagejpeg($rotated,$sourceFile,100);

/*---Rotate Origianl File also----*/
$upload=$_COOKIE['upload'];
$original = imagecreatefromjpeg($upload);
$rotated = imagerotate($original, $angle, $bgColour);
imagejpeg($rotated,$upload."rotate",100);
setcookie("upload", $upload."rotate", time()+3600);
}


Now the main issue is that after execution the rotation code new original rotation file is of double size and it's creating problem in processing next steps.


Can anyone help in this regard ?


I tried to explain as simple as I can but even it's not clear please let me know.


Note : Every time I am using the file stored in $_COOKIE['upload'], which is actual resolution.


I am trying to use the element to change the size of my logo if someone visits the website from mobile devices for example.


This is the code that I'm using :



<picture>
<source srcset="http://ift.tt/1F1Zmn0" media="(min-width: 1125px)">
<source srcset="http://ift.tt/1Mz2WhP" media="(min-width: 768px)">
<source srcset="http://ift.tt/1Mz2WhP" media="(max-width: 1123px)">
<img src="http://ift.tt/1F1Zmn0" alt="alt text examplle!">
</picture>


Problem is that the code works partially. For example works on my Android cell phone with latest version of Chrome but does't work on Iphone 6.


Works perfectly on desktop and if i resize de browser window it will change the logo. However, not the case on many new tablets.


Question is where is the problem ... Many thanks